- Vue.js 2 Web Development Projects
- Guillaume Chau
- 116字
- 2021-07-02 22:34:29
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.
推薦閱讀
- Java面向對象軟件開發
- Ceph Cookbook
- JMeter 性能測試實戰(第2版)
- Vue.js 3.x從入門到精通(視頻教學版)
- Lua程序設計(第4版)
- Scala謎題
- C語言程序設計學習指導與習題解答
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- C#程序設計(項目教學版)
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- Python程序設計與算法基礎教程(第2版)(微課版)
- Learning Node.js for .NET Developers
- Zabbix Performance Tuning
- Design Patterns and Best Practices in Java