Skip to content

Commit

Permalink
fix(input): numeric input v-model 为 null 时会报错
Browse files Browse the repository at this point in the history
  • Loading branch information
olivewind committed Aug 6, 2018
1 parent 7a7b329 commit d714d02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/dao-input/dao-numeric-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@
<script>
import DaoTriangle from './dao-triangle/dao-triangle.vue';
import { _toString } from '../../utils/assist';
function isInt(num) {
if (num === undefined) return false;
return /^(0|[1-9][0-9]*)$/.test(num >= 0 ? num : num.toString().slice(1));
return /^(0|[1-9][0-9]*)$/.test(num >= 0 ? num : _toString(num).slice(1));
}
function isFloat(num) {
return /^(-?\d+)(\.\d+)?$/.test(num);
}
function isEndWithDot(num) {
const arr = num.toString().split('.');
const arr = _toString(num).split('.');
if (arr.length === 2 && isInt(arr[0]) && arr[1] === '') {
return true;
}
Expand Down Expand Up @@ -117,7 +118,7 @@
onBlur() {
this.dirty = true;
if (this.type === 'float' && isEndWithDot(this.num)) {
this.preCheck(this.num.toString().split('.').shift());
this.preCheck(_toString(this.num).split('.').shift());
}
},
preCheck(num) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/assist.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { default as _chunk } from 'lodash/chunk';
export { default as _get } from 'lodash/get';
export { default as _flatten } from 'lodash/flatten';
export { default as _toNumber } from 'lodash/toNumber';
export { default as _toString } from 'lodash/toString';
export { default as _findIndex } from 'lodash/findIndex';
export { default as _merge } from 'lodash/merge';
export { default as _uniqBy } from 'lodash/uniqBy';

0 comments on commit d714d02

Please sign in to comment.