Commit 0b94936a0e5821718ad11a920f0284b923bc5f2b
1 parent
4935594e
fixed #28
fixed #28
Showing
1 changed file
with
19 additions
and
13 deletions
Show diff stats
components/input-number/input-number.vue
| ... | ... | @@ -175,7 +175,10 @@ |
| 175 | 175 | this.setValue(val); |
| 176 | 176 | }, |
| 177 | 177 | setValue (val) { |
| 178 | - this.value = val; | |
| 178 | + this.$nextTick(() => { | |
| 179 | + this.value = val; | |
| 180 | + }); | |
| 181 | + | |
| 179 | 182 | this.$emit('on-change', val); |
| 180 | 183 | }, |
| 181 | 184 | focus () { |
| ... | ... | @@ -201,6 +204,8 @@ |
| 201 | 204 | |
| 202 | 205 | if (isValueNumber(val)) { |
| 203 | 206 | val = Number(val); |
| 207 | + this.value = val; | |
| 208 | + | |
| 204 | 209 | if (val > max) { |
| 205 | 210 | this.setValue(max); |
| 206 | 211 | } else if (val < min) { |
| ... | ... | @@ -211,26 +216,27 @@ |
| 211 | 216 | } else { |
| 212 | 217 | event.target.value = this.value; |
| 213 | 218 | } |
| 214 | - } | |
| 215 | - }, | |
| 216 | - watch: { | |
| 217 | - value (val) { | |
| 219 | + }, | |
| 220 | + changeVal (val) { | |
| 218 | 221 | if (isValueNumber(val) || val === 0) { |
| 219 | 222 | val = Number(val); |
| 220 | 223 | const step = this.step; |
| 221 | - if (val + step > this.max) { | |
| 222 | - this.upDisabled = true; | |
| 223 | - } else if (val - step < this.min) { | |
| 224 | - this.downDisabled = true; | |
| 225 | - } else { | |
| 226 | - this.upDisabled = false; | |
| 227 | - this.downDisabled = false; | |
| 228 | - } | |
| 224 | + | |
| 225 | + this.upDisabled = val + step > this.max; | |
| 226 | + this.downDisabled = val - step < this.min; | |
| 229 | 227 | } else { |
| 230 | 228 | this.upDisabled = true; |
| 231 | 229 | this.downDisabled = true; |
| 232 | 230 | } |
| 233 | 231 | } |
| 232 | + }, | |
| 233 | + ready () { | |
| 234 | + this.changeVal(this.value); | |
| 235 | + }, | |
| 236 | + watch: { | |
| 237 | + value (val) { | |
| 238 | + this.changeVal(val); | |
| 239 | + } | |
| 234 | 240 | } |
| 235 | 241 | } |
| 236 | 242 | </script> |
| 237 | 243 | \ No newline at end of file | ... | ... |