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

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.

主站蜘蛛池模板: 红安县| 卢龙县| 兴化市| 柳林县| 大丰市| 绵阳市| 安庆市| 辽阳县| 中卫市| 贵州省| 康乐县| 开平市| 嘉定区| 绥滨县| 云龙县| 大港区| 拉萨市| 元氏县| 台江县| 安丘市| 平定县| 廊坊市| 宜兰市| 望都县| 桓台县| 博罗县| 桦甸市| 龙江县| 永胜县| 凤庆县| 甘南县| 岫岩| 玉溪市| 长阳| 陕西省| 祁阳县| 北碚区| 甘洛县| 拉孜县| 荆门市| 百色市|