5757 <view v-if =" showWordCount" class =" wd-input__count" >
5858 <text
5959 :class =" [
60- inputValue && String(inputValue).length > 0 ? 'wd-input__count-current' : '',
61- String(inputValue).length > maxlength! ? 'is-error' : ''
62- ]"
60+ inputValue && String(inputValue).length > 0 ? 'wd-input__count-current' : '',
61+ String(inputValue).length > maxlength! ? 'is-error' : ''
62+ ]"
6363 >
6464 {{ String(inputValue).length }}
6565 </text >
@@ -88,7 +88,7 @@ export default {
8888<script lang="ts" setup>
8989import wdIcon from ' ../wd-icon/wd-icon.vue'
9090import { computed , onBeforeMount , ref , watch } from ' vue'
91- import { isDef , objToStyle , pause } from ' ../common/util'
91+ import { isDef , objToStyle , pause , isEqual } from ' ../common/util'
9292import { useCell } from ' ../composables/useCell'
9393import { FORM_KEY , type FormItemRule } from ' ../wd-form/types'
9494import { useParent } from ' ../composables/useParent'
@@ -115,7 +115,7 @@ const isPwdVisible = ref<boolean>(false)
115115const clearing = ref <boolean >(false ) // 是否正在清空操作,避免重复触发失焦
116116const focused = ref <boolean >(false ) // 控制聚焦
117117const focusing = ref <boolean >(false ) // 当前是否激活状态
118- const inputValue = ref <string | number >(' ' ) // 输入框的值
118+ const inputValue = ref <string | number >(getInitValue () ) // 输入框的值
119119const cell = useCell ()
120120
121121watch (
@@ -130,8 +130,7 @@ watch(
130130 () => props .modelValue ,
131131 (newValue ) => {
132132 inputValue .value = isDef (newValue ) ? String (newValue ) : ' '
133- },
134- { immediate: true , deep: true }
133+ }
135134)
136135
137136const { parent : form } = useParent (FORM_KEY )
@@ -210,14 +209,13 @@ const labelStyle = computed(() => {
210209 : ' '
211210})
212211
213- onBeforeMount (() => {
214- initState ()
215- })
216-
217212// 状态初始化
218- function initState() {
219- inputValue .value = formatValue (inputValue .value )
220- emit (' update:modelValue' , inputValue .value )
213+ function getInitValue() {
214+ const formatted = formatValue (props .modelValue )
215+ if (! isValueEqual (formatted , props .modelValue )) {
216+ emit (' update:modelValue' , formatted )
217+ }
218+ return formatted
221219}
222220
223221function formatValue(value : string | number ) {
@@ -284,6 +282,9 @@ function onClickPrefixIcon() {
284282function handleClick(event : MouseEvent ) {
285283 emit (' click' , event )
286284}
285+ function isValueEqual(value1 : number | string , value2 : number | string ) {
286+ return isEqual (String (value1 ), String (value2 ))
287+ }
287288 </script >
288289
289290<style lang="scss" scoped>
0 commit comments