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

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.

主站蜘蛛池模板: 米泉市| 嘉荫县| 宁津县| 鹤庆县| 子洲县| 蒙阴县| 会昌县| 屏南县| 友谊县| 水城县| 延吉市| 伊川县| 济源市| 临高县| 梧州市| 嫩江县| 安塞县| 克山县| 横山县| 普格县| 东兰县| 平潭县| 嘉义县| 德惠市| 通城县| 汶川县| 新干县| 九龙县| 清原| 自治县| 闽清县| 高州市| 梅州市| 湘阴县| 湘潭县| 嫩江县| 广饶县| 海兴县| 光泽县| 堆龙德庆县| 武夷山市|