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

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.

主站蜘蛛池模板: 平武县| 龙里县| 汕头市| 江阴市| 耒阳市| 汝阳县| 绥棱县| 三原县| 德昌县| 当阳市| 大庆市| 土默特右旗| 东山县| 松江区| 洮南市| 成都市| 兴业县| 灌南县| 达拉特旗| 日喀则市| 上栗县| 赤水市| 涿鹿县| 贡嘎县| 阳谷县| 青铜峡市| 河曲县| 华宁县| 鹰潭市| 浦县| 明星| 上栗县| 郸城县| 大英县| 永丰县| 肥乡县| 湖南省| 湄潭县| 米泉市| 海淀区| 高台县|