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,7 +175,10 @@ | ||
| 175 | this.setValue(val); | 175 | this.setValue(val); |
| 176 | }, | 176 | }, |
| 177 | setValue (val) { | 177 | setValue (val) { |
| 178 | - this.value = val; | 178 | + this.$nextTick(() => { |
| 179 | + this.value = val; | ||
| 180 | + }); | ||
| 181 | + | ||
| 179 | this.$emit('on-change', val); | 182 | this.$emit('on-change', val); |
| 180 | }, | 183 | }, |
| 181 | focus () { | 184 | focus () { |
| @@ -201,6 +204,8 @@ | @@ -201,6 +204,8 @@ | ||
| 201 | 204 | ||
| 202 | if (isValueNumber(val)) { | 205 | if (isValueNumber(val)) { |
| 203 | val = Number(val); | 206 | val = Number(val); |
| 207 | + this.value = val; | ||
| 208 | + | ||
| 204 | if (val > max) { | 209 | if (val > max) { |
| 205 | this.setValue(max); | 210 | this.setValue(max); |
| 206 | } else if (val < min) { | 211 | } else if (val < min) { |
| @@ -211,26 +216,27 @@ | @@ -211,26 +216,27 @@ | ||
| 211 | } else { | 216 | } else { |
| 212 | event.target.value = this.value; | 217 | event.target.value = this.value; |
| 213 | } | 218 | } |
| 214 | - } | ||
| 215 | - }, | ||
| 216 | - watch: { | ||
| 217 | - value (val) { | 219 | + }, |
| 220 | + changeVal (val) { | ||
| 218 | if (isValueNumber(val) || val === 0) { | 221 | if (isValueNumber(val) || val === 0) { |
| 219 | val = Number(val); | 222 | val = Number(val); |
| 220 | const step = this.step; | 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 | } else { | 227 | } else { |
| 230 | this.upDisabled = true; | 228 | this.upDisabled = true; |
| 231 | this.downDisabled = true; | 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 | </script> | 242 | </script> |
| 237 | \ No newline at end of file | 243 | \ No newline at end of file |