- Vue.js 2 Web Development Projects
- Guillaume Chau
- 208字
- 2021-07-02 22:34:28
The current note
Now that we know which note is currently selected, we can replace the old content data property we created at the beginning. It would be very useful to have a computed property to easily access the selected note, so we will create one now:
- Add a new computed property called selectedNote that returns the note with an ID that matches our selectedId property:
computed: { ... selectedNote () { // We return the matching note with selectedId return this.notes.find(note => note.id === this.selectedId) }, }
note => note.id === this.selectedId is an arrow function from the ES2015 JavaScript version. Here, it takes a note argument and returns the result of the note.id === this.selectedId expression.
We need to replace the old content data property with selectedNote.content in our code.
- Start by modifying the editor in the template:
<textarea v-model="selectedNote.content"></textarea>
- Then, change the notePreview computed property to now use selectedNote:
notePreview () { // Markdown rendered to HTML return this.selectedNote ? marked(this.selectedNote.content) :
'' },
Now, the text editor and the preview pane will display the selected note when you click on it in the list.
You can safely remove the content data property, its watcher, and the saveNote method, which are no longer used in the app.
推薦閱讀
- Clojure Programming Cookbook
- Visual Basic .NET程序設計(第3版)
- Spring 5.0 By Example
- Java面向對象思想與程序設計
- 數據結構與算法JavaScript描述
- MySQL數據庫管理與開發(慕課版)
- Hands-On Automation Testing with Java for Beginners
- Getting Started with Laravel 4
- 新一代SDN:VMware NSX 網絡原理與實踐
- Developing SSRS Reports for Dynamics AX
- GitHub入門與實踐
- 算法設計與分析:基于C++編程語言的描述
- STM8實戰
- 例說FPGA:可直接用于工程項目的第一手經驗
- 每個人的Python:數學、算法和游戲編程訓練營