uniapp 的input组件在@input事件中限制用户可输入数值的范围,出现视图不更新的bug。

在input事件拿到用户输入的值,然后给input组件绑定的值赋值之前,判断用户输入的不能超过最大值,超过的话默认为100,,这个判断和赋值然后视图更新只能触发一次,之后在输入,发现值改了页面但是不更新。我擦了,v-model和:value都试过。都没用,网上描述的这个bug能追溯到19年。看来是个老bug。解决办法就是将赋值代码写在延时器中:

$set也试过 没有用

javascript 复制代码
inputfomatter(val) {//input事件函数
				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)
			},
相关推荐
kyriewen114 小时前
你点的“刷新”是假刷新?前端路由的瞒天过海术
开发语言·前端·javascript·ecmascript·html5
skywalk81636 小时前
Kotti Next的tinyfrontend前端模仿Kotti 首页布局还是不太好看,感觉比Kotti差一点
前端
RopenYuan8 小时前
FastAPI -API Router的应用
前端·网络·python
走粥8 小时前
clsx和twMerge解决CSS类名冲突问题
前端·css
Purgatory0019 小时前
layui select重新渲染
前端·layui
weixin199701080169 小时前
《中国供应商商品详情页前端性能优化实战》
前端·性能优化
赵孝正11 小时前
学习的本质是一个工程闭环:从模仿到内化的四阶段方法论(附风电实战案例)
前端·数据库·学习
csdn_aspnet12 小时前
Git二分法精准定位Bug,分享用git bisect快速锁定引入缺陷的提交,提升调试效率
git·bug·二分查找