Commit c97c42ab2e4e954aa62fc846b7473f8462353d8c
1 parent
456daf34
support InputNumber
support InputNumber
Showing
8 changed files
with
50 additions
and
14 deletions
Show diff stats
CHANGE.md
README.md
src/components/input-number/input-number.vue
... | ... | @@ -92,7 +92,8 @@ |
92 | 92 | return { |
93 | 93 | focused: false, |
94 | 94 | upDisabled: false, |
95 | - downDisabled: false | |
95 | + downDisabled: false, | |
96 | + currentValue: this.value | |
96 | 97 | }; |
97 | 98 | }, |
98 | 99 | computed: { |
... | ... | @@ -164,7 +165,7 @@ |
164 | 165 | } |
165 | 166 | |
166 | 167 | const targetVal = Number(e.target.value); |
167 | - let val = Number(this.value); | |
168 | + let val = Number(this.currentValue); | |
168 | 169 | const step = Number(this.step); |
169 | 170 | if (isNaN(val)) { |
170 | 171 | return false; |
... | ... | @@ -196,9 +197,11 @@ |
196 | 197 | }, |
197 | 198 | setValue (val) { |
198 | 199 | this.$nextTick(() => { |
199 | - this.value = val; | |
200 | + this.currentValue = val; | |
201 | + this.$emit('input', val); | |
200 | 202 | this.$emit('on-change', val); |
201 | - this.$dispatch('on-form-change', val); | |
203 | + // todo 事件 | |
204 | +// this.$dispatch('on-form-change', val); | |
202 | 205 | }); |
203 | 206 | }, |
204 | 207 | focus () { |
... | ... | @@ -224,7 +227,7 @@ |
224 | 227 | |
225 | 228 | if (isValueNumber(val)) { |
226 | 229 | val = Number(val); |
227 | - this.value = val; | |
230 | + this.currentValue = val; | |
228 | 231 | |
229 | 232 | if (val > max) { |
230 | 233 | this.setValue(max); |
... | ... | @@ -234,7 +237,7 @@ |
234 | 237 | this.setValue(val); |
235 | 238 | } |
236 | 239 | } else { |
237 | - event.target.value = this.value; | |
240 | + event.target.value = this.currentValue; | |
238 | 241 | } |
239 | 242 | }, |
240 | 243 | changeVal (val) { |
... | ... | @@ -250,11 +253,14 @@ |
250 | 253 | } |
251 | 254 | } |
252 | 255 | }, |
253 | - compiled () { | |
254 | - this.changeVal(this.value); | |
256 | + mounted () { | |
257 | + this.changeVal(this.currentValue); | |
255 | 258 | }, |
256 | 259 | watch: { |
257 | 260 | value (val) { |
261 | + this.currentValue = val; | |
262 | + }, | |
263 | + currentValue (val) { | |
258 | 264 | this.changeVal(val); |
259 | 265 | } |
260 | 266 | } | ... | ... |
src/index.js
... | ... | @@ -18,7 +18,7 @@ import Checkbox from './components/checkbox'; |
18 | 18 | // import Form from './components/form'; |
19 | 19 | import Icon from './components/icon'; |
20 | 20 | import Input from './components/input'; |
21 | -// import InputNumber from './components/input-number'; | |
21 | +import InputNumber from './components/input-number'; | |
22 | 22 | // import LoadingBar from './components/loading-bar'; |
23 | 23 | // import Menu from './components/menu'; |
24 | 24 | // import Message from './components/message'; |
... | ... | @@ -74,7 +74,7 @@ const iview = { |
74 | 74 | Icon, |
75 | 75 | // iInput: Input, |
76 | 76 | Input, |
77 | - // InputNumber, | |
77 | + InputNumber, | |
78 | 78 | // LoadingBar, |
79 | 79 | // Menu, |
80 | 80 | // MenuGroup: Menu.Group, | ... | ... |
test/app.vue
... | ... | @@ -25,6 +25,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; } |
25 | 25 | <li><router-link to="/alert">Alert</router-link></li> |
26 | 26 | <li><router-link to="/badge">Badge</router-link></li> |
27 | 27 | <li><router-link to="/tag">Tag</router-link></li> |
28 | + <li><router-link to="/input-number">InputNumber</router-link></li> | |
28 | 29 | </ul> |
29 | 30 | </nav> |
30 | 31 | <router-view></router-view> | ... | ... |
test/main.js
1 | +<template> | |
2 | + <div> | |
3 | + <Input-number :max="10" :min="-1" v-model="v1"></Input-number> | |
4 | + {{ v1 }} | |
5 | + <div @click="c">change v1</div> | |
6 | + <Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number> | |
7 | + </div> | |
8 | +</template> | |
9 | +<script> | |
10 | + export default { | |
11 | + props: {}, | |
12 | + data () { | |
13 | + return { | |
14 | + v1: 1, | |
15 | + v2: 1 | |
16 | + }; | |
17 | + }, | |
18 | + computed: {}, | |
19 | + methods: { | |
20 | + c () { | |
21 | + this.v1 = 5; | |
22 | + } | |
23 | + } | |
24 | + }; | |
25 | +</script> | |
0 | 26 | \ No newline at end of file | ... | ... |
test/routers/tag.vue