官术网_书友最值得收藏!

Deleting the note

This second feature is a bit more complicated because we need a new method:

  1. Add a button element after the rename text input:
      <button @click="removeNote" title="Remove note"><i        
class="material-icons">delete</i></button>

As you can see, we listen to the click event with the v-on shorthand (the @ character) that calls the removeNote method that we will create very soon. Also, we put an appropriate icon as the button content.

  1. Add a new removeNote method that asks the user for confirmation and then removes the currently selected note from the notes array using the splice standard array method:
      removeNote () {
        if (this.selectedNote && confirm('Delete the note?')) {
          // Remove the note in the notes array
          const index = this.notes.indexOf(this.selectedNote)
          if (index !== -1) {
            this.notes.splice(index, 1)
          }
        }
      }

Now, if you try deleting the current note, you should note that the following three things happen:

  • The note is removed from the note list on the left
  • The text editor and the preview pane are hidden
  • The note list has been saved according to the browser console
主站蜘蛛池模板: 海门市| 陕西省| 普安县| 莱西市| 乌拉特前旗| 平潭县| 大丰市| 南郑县| 临海市| 黄大仙区| 平山县| 福鼎市| 桃园县| 溧阳市| 灌阳县| 营口市| 孝感市| 阿荣旗| 晋宁县| 嫩江县| 余庆县| 徐汇区| 普陀区| 西乌珠穆沁旗| 甘孜县| 宝山区| 海宁市| 潜山县| 徐汇区| 新巴尔虎右旗| 东安县| 温州市| 西城区| 岳普湖县| 离岛区| 桂林市| 黄山市| 喀喇| 庆云县| 登封市| 襄樊市|