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

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.

主站蜘蛛池模板: 清远市| 临夏市| 彭州市| 邢台市| 建平县| 固镇县| 山东| 德阳市| 常州市| 康乐县| 乡宁县| 黄平县| 平阳县| 高尔夫| 中牟县| 都江堰市| 宁津县| 楚雄市| 康乐县| 丰宁| 淮滨县| 玉龙| 阜新市| 磐石市| 淮安市| 巩义市| 韶关市| 孟州市| 双峰县| 海南省| 凤山市| 呼和浩特市| 武城县| 台湾省| 城固县| 仁寿县| 兴宁市| 万安县| 怀仁县| 安陆市| 祁连县|