chushihua
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Vue JS Cookie</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
|
||||
</head>
|
||||
<body>
|
||||
<div>Counted to <strong>{{ counter }}</strong></div>
|
||||
<p>Refresh to see the same value!</p>
|
||||
<script src="example.build.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user