- 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.
推薦閱讀
- C語(yǔ)言程序設(shè)計(jì)實(shí)踐教程(第2版)
- 我的第一本算法書
- 看透JavaScript:原理、方法與實(shí)踐
- Android 7編程入門經(jīng)典:使用Android Studio 2(第4版)
- Instant QlikView 11 Application Development
- Windows Server 2012 Unified Remote Access Planning and Deployment
- R的極客理想:工具篇
- Easy Web Development with WaveMaker
- Programming with CodeIgniterMVC
- HTML5+CSS3+JavaScript 從入門到項(xiàng)目實(shí)踐(超值版)
- 交互設(shè)計(jì)師成長(zhǎng)手冊(cè):從零開始學(xué)交互
- 人件集:人性化的軟件開發(fā)
- Mastering VMware vSphere Storage
- SQL Server 2008數(shù)據(jù)庫(kù)應(yīng)用技術(shù)(第2版)
- Hadoop MapReduce v2 Cookbook(Second Edition)