forked from maple3142/vuejs-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
97 lines (91 loc) · 1.77 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>example</title>
<script src="https://unpkg.com/vuejs-storage"></script>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuex"></script>
</head>
<body>
<div id="app">
<div>
<span>Vue counter: {{count}}</span>
<button @click="add">add</button>
</div>
<div>
<span>Vuex counter: {{vuexcount}}</span>
<button @click="vuexadd">add</button>
</div>
</div>
<div id="app2">
<div>
<span>sessionStorage counter: {{count}} {{message}}</span>
<button @click="add">add</button>
</div>
</div>
<div>
Try open this page in another tab.
</div>
<script>
Vue.use(Vuex)
Vue.use(vuejsStorage)
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++
}
},
plugins: [
vuejsStorage({ namespace: 'vuex-app' ,keys: ['count']}) //call vuejsStorage with options will return a plugin
]
})
var app = new Vue({
el: '#app',
storage: { //provide options in storage
keys: ['count'],
namespace: 'app'
},
data: {
count: 0
},
methods: {
add: function () {
this.count++
},
vuexadd: function () {
store.commit('increment')
}
},
computed: {
vuexcount() {
return store.state.count
}
}
})
//advanced example
var app2 = new Vue({
el: '#app2',
data: {
message: 'Hello',
count: 0
},
storage: {
keys: ['count'],
driver: vuejsStorage.drivers.sessionStorage,
namespace: 'app2'
},
methods: {
add: function () {
this.count++
}
}
})
</script>
</body>
</html>