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

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
主站蜘蛛池模板: 乐平市| 资阳市| 亳州市| 阿坝| 郎溪县| 红河县| 赤峰市| 天峨县| 定西市| 敖汉旗| 象山县| 桂平市| 比如县| 巩留县| 抚顺县| 蕲春县| 陆良县| 额敏县| 新和县| 五家渠市| 新竹县| 汉阴县| 磴口县| 湟源县| 黔东| 双柏县| 云浮市| 随州市| 增城市| 阳信县| 厦门市| 安泽县| 北辰区| 天峨县| 鄂尔多斯市| 饶河县| 靖安县| 镇巴县| 禹城市| 谢通门县| 九台市|