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

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
主站蜘蛛池模板: 文山县| 舒城县| 周至县| 确山县| 余干县| 东辽县| 营口市| 萨嘎县| 株洲县| 衡水市| 铅山县| 永川市| 海宁市| 临夏市| 无锡市| 商水县| 天祝| 淮阳县| 阿克陶县| 宜丰县| 合山市| 贵阳市| 威宁| 柳河县| 新绛县| 白水县| 彭阳县| 阳泉市| 五常市| 金坛市| 吕梁市| 洛隆县| 云阳县| 定南县| 唐河县| 忻城县| 伊川县| 昌图县| 东莞市| 湘阴县| 道孚县|