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

Saving the selection

It would be very handy if our app could select the note that was selected last time. We just need to store and load the selectedId data property used to store the ID of the selected note. That's right! Once more, we will use a watcher to trigger the save:

watch: {
  ...

  // Let's save the selection too
  selectedId (val) {
    localStorage.setItem('selected-id', val)
  },
}

Also, we will restore the value when the property is initialized:

data () {
  return {
    notes: JSON.parse(localStorage.getItem('notes')) || [],
    selectedId: localStorage.getItem('selected-id') || null,
  }
},

It's ready! Now, when you refresh the app, it should look exactly how you left it, with the same note selected.

主站蜘蛛池模板: 准格尔旗| 武功县| 井研县| 临潭县| 巴马| 陇西县| 安达市| 天祝| 阿克陶县| 柳河县| 井研县| 灌云县| 襄城县| 陵川县| 广平县| 安西县| 峨眉山市| 驻马店市| 康乐县| 元朗区| 青州市| 宜兰市| 吉林市| 鄂尔多斯市| 互助| 万山特区| 广丰县| 来凤县| 湘潭县| 比如县| 景德镇市| 莫力| 江永县| 荥阳市| 临邑县| 高要市| 山西省| 腾冲县| 盘锦市| 庆城县| 宿松县|