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

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.

主站蜘蛛池模板: 临沭县| 靖远县| 顺平县| 思茅市| 阿尔山市| 陆川县| 辽宁省| 宝兴县| 黔东| 瓦房店市| 宾阳县| 那曲县| 乌鲁木齐市| 开化县| 城口县| 青河县| 三台县| 盐边县| 宝兴县| 青岛市| 岳西县| 南安市| 宜春市| 铜陵市| 盖州市| 平陆县| 定日县| 济源市| 永丰县| 顺义区| 黎平县| 灵武市| 罗甸县| 乡宁县| 靖西县| 疏附县| 宜城市| 玛多县| 邓州市| 宝兴县| 喀喇|