forked from oarepo/vue-query-synchronizer
/
Home.vue
143 lines (140 loc) · 4.4 KB
/
Home.vue
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
<div class="home">
<br>
Write anything here and watch the addressbar. Later <a href="/">reload the application</a>
to see that the default value in the first field was taken from the local storage.<br><br>
<table>
<tr>
<td>
Field stored to the local storage:
</td>
<td>
<input v-model="$query.search"><br><br>
</td>
</tr>
<tr>
<td>
Simple text field
</td>
<td>
<input v-model="$query.search2"><br><br>
</td>
</tr>
<tr>
<td>
Number field with the default value of 10:
</td>
<td>
<input type="number" v-model="$query.num"><br><br>
</td>
</tr>
<tr>
<td>
Checkbox:
</td>
<td>
<input type="checkbox" v-model="$query.check"><br><br>
</td>
</tr>
<tr>
<td>
Array (multiple selection, control-click for selecting both values):
</td>
<td>
<select multiple v-model="$query.option">
<option value="first">First choice</option>
<option value="second">Second choice</option>
</select><br><br>
</td>
</tr>
<tr>
<td>
Comma-separated array (multiple selection, control-click for selecting both values):
</td>
<td>
<select multiple v-model="$query.option2">
<option value="first">First choice</option>
<option value="second">Second choice</option>
</select><br><br>
</td>
</tr>
<tr>
<td>
Space-separated array (multiple selection, control-click for selecting both values):
</td>
<td>
<select multiple v-model="$query.option3">
<option value="first">First choice</option>
<option value="second">Second choice</option>
</select><br><br>
</td>
</tr>
<tr>
<td>
Add and remove (the query param is called dynarr):
</td>
<td>
<input v-model="tmp" placeholder="Enter value"><br><br>
<button @click="$query.addValue('dynarr', tmp)">Add</button>
<button @click="$query.removeValue('dynarr', tmp)">Remove</button>
<br>
</td>
</tr>
</table>
<br><br>
<button @click="convert">Convert simple text field to numeric model (can be used to, for example, define
datatype later)
</button>
<br><br>
query equals:
<pre>{{ rawQuery }}</pre>
own keys:
<pre>
{{ currentKeys }}
</pre>
stringified query:
<pre>
{{ JSON.stringify($query, null, 4) }}
</pre>
</div>
</template>
<script>
import { IntDatatype, CommaArrayDatatype } from '@oarepo/vue-query-synchronizer'
export default {
name: 'home',
components: {},
props: {
another: String
},
data: function () {
return {
tmp: '',
currentKeys: []
}
},
mounted() {
this.$query.define('dynarr', CommaArrayDatatype, [])
this.currentKeys = Object.getOwnPropertyNames(this.$query)
console.log(this.currentKeys, JSON.stringify(this.$query))
},
methods: {
convert() {
this.$query.define('search2', IntDatatype)
}
},
computed: {
rawQuery() {
return this.$rawQuery
}
},
watches: {
rawQuery: {
deep: true,
handler: () => {
console.log('current keys called with', this.$query)
this.currentKeys = Object.getOwnPropertyNames(this.$query)
}
}
}
}
</script>