setFormatter 为兼容微信小程序而暴露的内部方法
mounted() {
//如果是在页面则使用onReady
this.$refs.Input.setFormatter(this.formate)
},
methods: {
formate(e){
if(parseInt(e)>parseInt(this.ticketInfo.num)){
uni.showToast({
title: '不能大于'+this.ticketInfo.num,
icon:'none'
})
return parseInt(this.ticketInfo.num)
}else{
return parseInt(e)
}
}
<u-input
ref="Input"
type="number"
border="none"
v-model="value"
@change="change"
inputAlign='center'
color='#030303'
fontSize='30rpx'
>
<!-- <text slot='suffix'>张</text> -->
</u-input>
文章讲述了在微信小程序开发中,如何在`mounted`生命周期钩子中使用`setFormatter`方法对输入框进行格式化,并实现输入数值不超过特定值的验证功能。
540

被折叠的 条评论
为什么被折叠?



