提交 983c1799 编写于 作者: Q qiang

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

上级 77c4c8c4
......@@ -52,7 +52,10 @@ const UniViewJSBridgeSubscribe = function () {
const FOCUS_DELAY = 200
let startTime: number
function getValueString(value: any) {
function getValueString(value: any, type: string) {
if (type === 'number' && isNaN(Number(value))) {
value = ''
}
return value === null ? '' : String(value)
}
......@@ -185,7 +188,9 @@ function useBase(
var maxlength = Number(props.maxlength)
return isNaN(maxlength) ? 140 : maxlength
})
const value = getValueString(props.modelValue) || getValueString(props.value)
const value =
getValueString(props.modelValue, props.type) ||
getValueString(props.value, props.type)
const state: State = reactive({
value,
valueOrigin: value,
......@@ -218,7 +223,7 @@ function useValueSync(
trigger: CustomEventTrigger
) {
const valueChangeFn = debounce((val: any) => {
state.value = getValueString(val)
state.value = getValueString(val, props.type)
}, 100)
watch(() => props.modelValue, valueChangeFn)
watch(() => props.value, valueChangeFn)
......
import { extend, hyphenate } from '@vue/shared'
import { Ref, ref, computed } from 'vue'
import { Ref, ref, computed, watch } from 'vue'
import { defineBuiltInComponent } from '../../helpers/component'
import {
props as fieldProps,
......@@ -107,6 +107,14 @@ export default /*#__PURE__*/ defineBuiltInComponent({
}
}
})
watch(
() => state.value,
(value) => {
if (props.type === 'number' && !(cache.value === '-' && value === '')) {
cache.value = value
}
}
)
const NUMBER_TYPES = ['number', 'digit']
const step = computed(() =>
NUMBER_TYPES.includes(props.type) ? '0.000000000000000001' : ''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册