- Vue.js 2 Web Development Projects
- Guillaume Chau
- 173字
- 2021-07-02 22:34:29
Deleting the note
This second feature is a bit more complicated because we need a new method:
- 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.
- 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
推薦閱讀
- Learning Informatica PowerCenter 10.x(Second Edition)
- Practical Game Design
- Full-Stack React Projects
- Mastering KnockoutJS
- 自然語言處理Python進(jìn)階
- Oracle 18c 必須掌握的新特性:管理與實(shí)戰(zhàn)
- Kubernetes源碼剖析
- Natural Language Processing with Python Quick Start Guide
- IBM Cognos TM1 Developer's Certification guide
- QlikView Unlocked
- Photoshop CC移動UI設(shè)計(jì)案例教程(全彩慕課版·第2版)
- Android系統(tǒng)下Java編程詳解
- Mastering Android Studio 3
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)
- Implementing Microsoft Dynamics NAV(Third Edition)