-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-vue2.html
77 lines (74 loc) · 2.11 KB
/
example-vue2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 2.x Sync Query Mixin Example</title>
</head>
<body>
<h4>Modify both input boxes and query string of the URL, to see how they keep in sync</h4>
<div id="app"><router-view></router-view></div>
<script type="text/x-template" id="app-tpl">
<div>
<fieldset>
<code>$route.query: {{ $route.query }}</code>
</fieldset>
<fieldset>
<code>$vm.$data: {{ $data }}</code><hr>
a: <input type="text" v-model="a"> 
b: <input type="text" v-model="b"> 
c: <input type="text" v-model="c"><br>
d: {{ d }} <button @click="d.push(4)">push</button><br>
e: <input type="text" v-model="e"> 
f: <input type="text" v-model="f"> 
g: <input type="text" v-model="g">
</fieldset>
</div>
</script>
<script src="//cdn.bootcss.com/vue/2.2.6/vue.js"></script>
<script src="//cdn.bootcss.com/vue-router/2.3.1/vue-router.min.js"></script>
<script src="./dist/vue-sync-query-mixin.min.js"></script>
<pre id="script" style="font-size: 12px">
/**************** Source Code ****************/
var App = {
name: 'App',
template: '#app-tpl',
mixins: [VueSyncQuery.default],
data: function () {
return { a: 1, b: 2, c: 3, d: [4, 4, 4, 4], e: 5, f: 6, g: 7 };
},
mounted: function () {
this.syncQuery('a');
this.syncQuery(['b', 'c']);
this.syncQuery({
localField: 'd',
queryField: 'dddd',
local2query: function (v) {
return v.join(',');
},
query2local: function (v) {
// return falsy value meaning restore the default value
return v ? v.split(',') : null;
}
});
this.syncQuery([
'e', // same as { localField: 'e', queryField: 'e' }
{ localField: 'f', queryField: 'ffffff' }
]);
this.syncQuery({
localField: 'g',
queryField: 'ggggggg',
local2query: { immediate: true }
});
}
};
new Vue({
el: '#app',
router: new VueRouter({ routes: [{ path: '/', component: App }] })
});
Vue.config.devtools = true;
</pre>
<script>
eval(document.getElementById('script').innerHTML);
</script>
</body>
</html>