PC/node_modules/vue-js-cookie/example/example.js
2026-01-26 23:20:48 +08:00

33 lines
564 B
JavaScript

var Vue = require('vue')
var VueCookie = require('../')
Vue.use(VueCookie)
var COUNTER_NAME = 'vue-js-counter'
new Vue({
el: 'div',
data: {
counter: 0
},
ready: function () {
if (this.$cookie.get(COUNTER_NAME)) {
this.counter = parseInt(this.$cookie.get(COUNTER_NAME), 10)
}
setInterval(function () {
this.increment()
}.bind(this), 1000)
},
methods: {
increment: function () {
this.counter += 1
}
},
watch: {
counter: function (value) {
this.$cookie.set(COUNTER_NAME, value)
}
}
})