fix: 🐛 修复 Textarea 设置为 null 时,显示字数限制显示错误问题 (#1004)

 Closes: #1003
This commit is contained in:
小马 2025-05-06 11:03:00 +08:00 committed by GitHub
parent a200337863
commit 60f2fe61ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -181,7 +181,7 @@ const currentLength = computed(() => {
* 使用Array.from处理多码元字符以获取正确的长度
* @link https://github.com/Moonofweisheng/wot-design-uni/issues/933
*/
return Array.from(String(formatValue(props.modelValue) || '')).length
return Array.from(String(formatValue(props.modelValue))).length
})
const rootClass = computed(() => {
@ -224,6 +224,7 @@ function initState() {
}
function formatValue(value: string | number) {
if (value === null || value === undefined) return ''
const { maxlength, showWordLimit } = props
if (showWordLimit && maxlength !== -1 && String(value).length > maxlength) {
return value.toString().substring(0, maxlength)