vuelsvue本地储存示例
vue-ls 是什么: 一个vue封装的本地储存的方法。。安装方法:NPMnpm install vue-ls --saveYarnyarn add vue-lsBowerbower install vue-ls --save++++++++++++++++++++++++++++++++++++++++++++++++++++++++++一个简单的示例:不用废话,直接上代码:vue引用+调用方法:import VueLocalStorage from 'vue-ls';options = { namespace: 'vuejs__'};Vue.use(VueLocalStorage, options);//or//Vue.use(VueLocalStorage);HTML:diva href="https://www.npmjs.com/package/vue-ls"Vue localstorage plugin/a/divdiv id="app"counter: pw_counterdivbutton type="button" @click="increment()"Increment/buttonbutton type="button" @click="decrement()"Decrement/button/div/divJS:Vue.use(VueLocalStorage);new Vue({el: '#app',//绑定视图变量data: function() {return {counter: 0};},//监听视图变量中的变化,并绑定到$ls内watch: {counter: function(val) {this.$ls.set('counter', val)}},//在视图渲染创建后将把$el内的变量重新赋值给datacreated: function() {this.counter = this.$ls.get('counter', 0);var _this = this;this.$ls.on('counter', function(val) {_this.counter = val;});},//用户自定义函数methods: {increment: function() {this.counter++;},decrement: function() {this.counter--;}}});
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

