- Vue.js 2 Web Development Projects
- Guillaume Chau
- 183字
- 2021-07-02 22:34:28
Selecting a note
When a note is selected, it becomes the context of the middle and right panes of the app--the text editor modifies its content, and the preview pane displays its formatted markdown. Let's implement this behavior!
- Add a new data property called selectedId that will hold the ID of the selected note:
data () { return { content: localStorage.getItem('content') || 'You can write in
**markdown**', notes: [], // Id of the selected note selectedId: null, } },
We could have created a selectedNote property instead, holding the note object, but it would have made the saving logic more complex, with no benefit.
- We need a new method that will be called when we click on a note in the list to select ID. Let's call it selectNote:
methods: { ... selectNote (note) { this.selectedId = note.id }, }
- Like we did for the add note button, we will listen for the click event with the v-on directive on each note item in the list:
<p class="notes"> <p class="note" v-for="note of notes"
@click="selectNote(note)">{{note.title}}</p> </p>
Now, you should see the ;updated selectedId data property when you click on a note.
推薦閱讀
- Django+Vue.js商城項目實戰
- Oracle WebLogic Server 12c:First Look
- Hyper-V 2016 Best Practices
- Vue.js入門與商城開發實戰
- Python語言程序設計
- PHP網絡編程學習筆記
- Functional Programming in JavaScript
- Mastering Kali Linux for Web Penetration Testing
- SQL Server從入門到精通(第3版)
- 移動界面(Web/App)Photoshop UI設計十全大補
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Working with Odoo
- 機器學習與R語言實戰
- Visual Basic程序設計習題與上機實踐
- 代替VBA!用Python輕松實現Excel編程