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

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.

主站蜘蛛池模板: 肃宁县| 肥城市| 正阳县| 鸡西市| 宣化县| 资阳市| 洛南县| 甘谷县| 乌拉特中旗| 岗巴县| 深泽县| 绥中县| 南召县| 凤翔县| 石台县| 东安县| 商水县| 金溪县| 兴化市| 靖西县| 马山县| 马山县| 漳平市| 桂东县| 阿城市| 巴彦淖尔市| 兴隆县| 景东| 郸城县| 姜堰市| 永寿县| 义乌市| 涿州市| 堆龙德庆县| 宝坻区| 纳雍县| 枞阳县| 阿拉尔市| 徐水县| 孟津县| 万源市|