提交 ddfedb8f 编写于 作者: Q qiang

fix(h5): 修复部分情况下input显示数值错误的问题(question/140366)

上级 b497230d
......@@ -148,6 +148,11 @@ export default {
maxlength (value) {
const realValue = this.valueSync.slice(0, parseInt(value, 10))
realValue !== this.valueSync && (this.valueSync = realValue)
},
valueSync (value) {
if (this.type === 'number' && !(this.cachedValue === '-' && value === '')) {
this.cachedValue = value
}
}
},
created () {
......
......@@ -71,7 +71,7 @@ export default {
data () {
return {
composing: false,
valueSync: this._getValueString(this.value),
valueSync: this._getValueString(this.value, this.type),
focusSync: this.focus,
// Safari 14 以上修正禁用状态颜色
fixColor: String(navigator.vendor).indexOf('Apple') === 0 && CSS.supports('image-orientation:from-image')
......@@ -117,7 +117,7 @@ export default {
},
created () {
const valueChange = this.__valueChange = debounce((val) => {
this.valueSync = this._getValueString(val)
this.valueSync = this._getValueString(val, this.type)
}, 100)
this.$watch('value', valueChange)
this.__triggerInput = throttle(($event, detail) => {
......@@ -145,7 +145,10 @@ export default {
}
},
methods: {
_getValueString (value) {
_getValueString (value, type) {
if (type === 'number' && isNaN(Number(value))) {
value = ''
}
return value === null ? '' : String(value)
},
_initField (el) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册