-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-vue1.html
69 lines (68 loc) · 2 KB
/
example-vue1.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 1.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">
<fieldset>
<code>$route.query: {{ $route.query | json }}</code>
</fieldset>
<fieldset>
<code>$vm.$data: {{ $data | json }}</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 | json }} <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 src="//cdn.bootcss.com/vue/1.0.28/vue.min.js"></script>
<script src="//cdn.bootcss.com/vue-router/0.7.13/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 = {
mixins: [VueSyncQuery.default],
data: function () {
return { a: 1, b: 2, c: 3, d: [4, 4, 4, 4], e: 5, f: 6, g: 7 };
},
ready: 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 }
});
}
};
var router = new VueRouter();
router.map({ '/': { component: {} } });
router.start(App, '#app');
Vue.config.devtools = true;
</pre>
<script>
eval(document.getElementById('script').innerHTML);
</script>
</body>
</html>