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:
<div class="notes"> <div class="note" v-for="note of notes"
@click="selectNote(note)">{{note.title}}</div> </div>
Now, you should see the ;updated selectedId data property when you click on a note.