在input事件拿到用戶輸入的值,然后給input組件綁定的值賦值之前,判斷用戶輸入的不能超過最大值,超過的話默認(rèn)為100,,這個(gè)判斷和賦值然后視圖更新只能觸發(fā)一次,之后在輸入,發(fā)現(xiàn)值改了頁面但是不更新。我擦了,v-model和:value都試過。都沒用,網(wǎng)上描述的這個(gè)bug能追溯到19年??磥硎莻€(gè)老bug。解決辦法就是將賦值代碼寫在延時(shí)器中:文章來源:http://www.zghlxwxcb.cn/news/detail-602385.html
$set也試過 沒有用文章來源地址http://www.zghlxwxcb.cn/news/detail-602385.html
inputfomatter(val) {//input事件函數(shù)
console.log("input事件");
this.questList[this.questIndex].options[0].value = Number(val.target.value)
if (val.detail.value.length > 0) { //清除按鈕顯隱
this.showClearIcon = true;
} else {
this.showClearIcon = false;
}
if (Number(val.target.value) < this.questList[this.questIndex].rulerMinValue) { //如果用戶輸入的值小于最小值,則賦值為最小值
setTimeout(() => { this.questList[this.questIndex].options[0].value = this.questList[this.questIndex].rulerMinValue }, 0) //不這么寫,輸入的超過最大值只能重置一次,之后,雖重置了值,但是頁面不更新
// this.questList[this.questIndex].options[0].value = this.questList[this.questIndex].rulerMinValue
}
if (Number(val.target.value) > this.questList[this.questIndex].rulerMaxValue) { //如果用戶輸入的值大于最大值,則賦值為最大值
setTimeout(() => { this.questList[this.questIndex].options[0].value = this.questList[this.questIndex].rulerMaxValue }, 0)
// this.questList[this.questIndex].options[0].value = this.questList[this.questIndex].rulerMaxValue
// this.$set(this.questList[this.questIndex].options[0], 'value', this.questList[this.questIndex].rulerMaxValue)
}
setTimeout(() => { this.questList[this.questIndex].options[0].value = this.$toFixed(Number(this.questList[this.questIndex].options[0].value), 2) }, 0)
},
到了這里,關(guān)于uniapp 的input組件在@input事件中限制用戶可輸入數(shù)值的范圍,出現(xiàn)視圖不更新的bug。的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!