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

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.

主站蜘蛛池模板: 舟曲县| 东乡族自治县| 泰安市| 阿拉善左旗| 密云县| 璧山县| 正定县| 中牟县| 桐柏县| 屯昌县| 台江县| 若羌县| 高邑县| 循化| 阆中市| 兰西县| 黄浦区| 河津市| 宿迁市| 成武县| 汾阳市| 武乡县| 颍上县| 香河县| 易门县| 伊川县| 满洲里市| 区。| 微山县| 太保市| 资源县| 浦城县| 依兰县| 伊吾县| 太湖县| 无为县| 凤庆县| 鸡泽县| 大足县| 香港| 蓝田县|