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

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.

主站蜘蛛池模板: 阿合奇县| 汤原县| 高邑县| 桦南县| 石城县| 克山县| 福安市| 鹤壁市| 黄石市| 通山县| 遂溪县| 昌邑市| 全椒县| 六安市| 新余市| 望奎县| 康乐县| 齐河县| 永济市| 宣汉县| 永昌县| 台中县| 张家界市| 大厂| 平邑县| 南和县| 红原县| 丁青县| 黔西| 富民县| 伊春市| 彝良县| 大关县| 吐鲁番市| 长汀县| 安顺市| 顺义区| 滨海县| 涪陵区| 察雅县| 都兰县|