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

The current note

Now that we know which note is currently selected, we can replace the old content data property we created at the beginning. It would be very useful to have a computed property to easily access the selected note, so we will create one now:

  1. Add a new computed property called selectedNote that returns the note with an ID that matches our selectedId property:
      computed: {
        ...

        selectedNote () {
          // We return the matching note with selectedId
          return this.notes.find(note => note.id === this.selectedId)
        },
      }

note => note.id === this.selectedId is an arrow function from the ES2015 JavaScript version. Here, it takes a note argument and returns the result of the note.id === this.selectedId expression.

We need to replace the old content data property with selectedNote.content in our code.

  1. Start by modifying the editor in the template:
      <textarea v-model="selectedNote.content"></textarea>
  1. Then, change the notePreview computed property to now use selectedNote:
      notePreview () {
        // Markdown rendered to HTML
        return this.selectedNote ? marked(this.selectedNote.content) :          
'' },

Now, the text editor and the preview pane will display the selected note when you click on it in the list.

You can safely remove the content data property, its watcher, and the saveNote method, which are no longer used in the app.

主站蜘蛛池模板: 崇州市| 和田市| 迁安市| 吴堡县| 澄城县| 文化| 于田县| 乐至县| 平原县| 徐汇区| 二连浩特市| 辽宁省| 安图县| 水富县| 德化县| 正镶白旗| 柳江县| 平谷区| 资源县| 讷河市| 昌都县| 上杭县| 荥经县| 拜泉县| 湘潭县| 宝坻区| 宝应县| 开远市| 阿巴嘎旗| 秦皇岛市| 宁阳县| 昭通市| 乌海市| 忻州市| 萍乡市| 株洲县| 甘洛县| 云梦县| 镇坪县| 武定县| 翁源县|