零、前提:
實現input輸入數字不大于10000(需要配合type=number,maxlength=5,這里沒寫)
一、探究代碼:
<input v-model="model1" @input="changeModel1" placeholder="請輸入拒收件數"/>
const model1=ref(0)
const changeModel1=()=>{console.log('model1',model1.value)//是否去掉此處if判斷if(model1.value>10000){console.log('model1>10000')model1.value = model1.value.slice(0, 4);console.log('model1',model1.value)}
}
?ps:vue2也試了一下,跟vue2還是vue3無關
二、探究結果:
1.web端/uniapp轉微信小程序-未加if判斷-及時更新
?2.web端-加了if判斷-及時更新
uniapp轉微信小程序-加了if判斷-未及時更新
三、AI分析原因:
四、解決方案:
解決uniapp轉微信小程序-加了if判斷-未及時更新:加一個nextTick(()=>{})即可
import { ref, nextTick } from 'vue';const changeModel1=()=>{if(model1.value>10000){nextTick(() => {model1.value = model1.value.slice(0, 4);}}
}