官术网_书友最值得收藏!

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!

  1. 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.

  1. 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
        },
      }
  1. 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.

主站蜘蛛池模板: 岳阳县| 遵化市| 金沙县| 海盐县| 全州县| 大足县| 景德镇市| 安福县| 辽阳县| 玛曲县| 利津县| 三都| 得荣县| 沾益县| 宁陵县| 康马县| 抚松县| 扎囊县| 辽阳市| 金溪县| 永靖县| 福建省| 禄丰县| 长丰县| 麻城市| 洪洞县| 清流县| 嘉善县| 玛曲县| 洛南县| 牙克石市| 洛阳市| 桃源县| 南康市| 延津县| 龙江县| 顺昌县| 定远县| 育儿| 彩票| 怀柔区|