Commit 7adf94a2919729b9d2c61d77663d1379d9762565
1 parent
c020a58d
update
Showing
2 changed files
with
30 additions
and
12 deletions
Show diff stats
examples/routers/input-number.vue
... | ... | @@ -54,8 +54,20 @@ |
54 | 54 | <InputNumber v-model="value3" style="width: 200px" placeholder="Enter something..."></InputNumber> --> |
55 | 55 | |
56 | 56 | |
57 | - <InputNumber v-model="valueNull" style="width: 200px" :min='-1000' :max='10000' :precision='2' ></InputNumber> | |
57 | + <InputNumber v-model="valueNull" style="width: 200px" :min='1' :max='10000' :precision='2' ></InputNumber> | |
58 | 58 | <InputNumber v-model="valueNull" style="width: 200px" ></InputNumber> |
59 | + <div style="margin:10px 0px"> | |
60 | + <InputNumber | |
61 | + :max="10000" | |
62 | + v-model="value9" | |
63 | + :formatter="value => `$ ${value}`.replace(/B(?=(d{3})+(?!d))/g, ',')" | |
64 | + :parser="value => value.replace(/\$s?|(,*)/g, '')"></InputNumber> | |
65 | + <InputNumber | |
66 | + :max="100" | |
67 | + v-model="value10" | |
68 | + :formatter="value => `${value}%`" | |
69 | + :parser="value => value.replace('%', '')"></InputNumber> | |
70 | + </div> | |
59 | 71 | </div> |
60 | 72 | </template> |
61 | 73 | <script> |
... | ... | @@ -69,16 +81,18 @@ |
69 | 81 | formatter: (value) => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ','), |
70 | 82 | parser: (value) => value.replace(/\$\s?|(,*)/g, ''), |
71 | 83 | formatter2: (value) => `${value}%`, |
72 | - parser2: (value) => value.replace('%', '') | |
73 | - } | |
84 | + parser2: (value) => value.replace('%', ''), | |
85 | + value9: 1000, | |
86 | + value10: 100 | |
87 | + }; | |
74 | 88 | }, |
75 | 89 | methods: { |
76 | 90 | focus (e) { |
77 | - e.target.select() | |
91 | + e.target.select(); | |
78 | 92 | }, |
79 | 93 | change (v) { |
80 | - console.log(v) | |
94 | + console.log(v); | |
81 | 95 | } |
82 | 96 | } |
83 | - } | |
97 | + }; | |
84 | 98 | </script> | ... | ... |
src/components/input-number/input-number.vue
... | ... | @@ -250,13 +250,16 @@ |
250 | 250 | setValue (val) { |
251 | 251 | // 如果 step 是小数,且没有设置 precision,是有问题的 |
252 | 252 | if (val && !isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision)); |
253 | - | |
253 | + | |
254 | 254 | const {min, max} = this; |
255 | - if (val > max) { | |
256 | - val = max; | |
257 | - } else if (val < min) { | |
258 | - val = min; | |
259 | - } | |
255 | + if (val!==null) { | |
256 | + if (val > max) { | |
257 | + val = max; | |
258 | + } else if (val < min) { | |
259 | + val = min; | |
260 | + } | |
261 | + } | |
262 | + | |
260 | 263 | this.$nextTick(() => { |
261 | 264 | this.currentValue = val; |
262 | 265 | this.$emit('input', val); |
... | ... | @@ -282,6 +285,7 @@ |
282 | 285 | } |
283 | 286 | }, |
284 | 287 | change (event) { |
288 | + | |
285 | 289 | if (event.type == 'input') return; |
286 | 290 | let val = event.target.value.trim(); |
287 | 291 | if (this.parser) { | ... | ... |