- 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.
推薦閱讀
- Modular Programming in Java 9
- 小程序開發原理與實戰
- NGUI for Unity
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- 精通Spring:Java Web開發與Spring Boot高級功能
- 量子計算機編程:從入門到實踐
- 大話代碼架構:項目實戰版
- C語言程序設計實驗指導
- Hands-On ROS for Robotics Programming
- ASP.NET Core 2 High Performance(Second Edition)
- Appcelerator Titanium Smartphone App Development Cookbook
- jBPM6 Developer Guide
- 區塊鏈原理、設計與應用
- Java性能權威指南
- HTML+CSS+JavaScript前端開發(慕課版)