解決方法
1.延遲修改,利用setTimeout
2.異步修改,利用this.$nextTick
<template>
<view>
<input v-modal="num" type="number" placeholder="請(qǐng)輸入" :maxlength="3" @input="onInputOne" />
<input v-modal="discount" type="number" placeholder="請(qǐng)輸入" :maxlength="3" @input="onInputTwo" />
</view>
</template>
<script>
export default {
data() {
return {
num: '',
discount: ''
}
},
methods: {
// 這里舉例折扣大于0,但是小于10,默認(rèn)最小值為0,最大值為9.9
// 第一種方法使用延時(shí),H5端有效,但App端不是很完美,其他端未測(cè)
onInputOne() {
if (Number(this.num) < 0) {
this.num = '0'
} else if (Number(this.num) >= 10) {
setTimeout(() => { // 設(shè)置延遲10ms有效,App端設(shè)置0實(shí)測(cè)無(wú)效
this.num = '9.9'
}, 10)
}
},
// 第二種方法使用異步修改,利用this.$nextTick實(shí)現(xiàn)
onInputTwo() {
if (Number(this.num) < 0) {
this.num = '0'
} else if (Number(this.num) >= 10) { // APP,H5端實(shí)測(cè)有用
this.$nextTick(() => {
this.num = '9.9'
})
}
}
}
}
</script>
<style>
</style>
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-427176.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-427176.html
到了這里,關(guān)于uniapp App端 解決input@input事件動(dòng)態(tài)修改值不生效的問(wèn)題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!