vue中使用localstorage
1、store.js(读取写入到localstorage)
const STORAGE_KEY="todos-vuejs" export default{ fetch(){ return JSON.parse(window.localStorage.getItem( STORAGE_KEY||"[]")) }, save(items){ window.localStorage.setItem(STORAGE_KEY,JSON.stringify(items)) } }
2、App.vue
"app">{{title}}
"title">
"title">
"text" v-model="newItem" v-on:keyup.enter="addNew">
- for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)"> {{item.label}}