- 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.
推薦閱讀
- 玩轉Scratch少兒趣味編程
- AngularJS入門與進階
- Java系統分析與架構設計
- SQL Server 2016從入門到精通(視頻教學超值版)
- C語言從入門到精通(第4版)
- Python 3破冰人工智能:從入門到實戰
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- Yocto for Raspberry Pi
- Active Directory with PowerShell
- SQL Server數據庫管理與開發兵書
- 智能搜索和推薦系統:原理、算法與應用
- 區塊鏈項目開發指南
- Simulation for Data Science with R
- 跟戴銘學iOS編程:理順核心知識點
- 創意UI Photoshop玩轉移動UI設計