学无先后,达者为师

网站首页 编程语言 正文

input 限制输入 小数点后两位

作者:嘿,小苹果 更新时间: 2022-05-06 编程语言
<u--input placeholder="输入积分数量" type='number' inputAlign='right' border="none" clearable
						v-model="countnum" @change="change"  @input="inputNumber">u--input>
change(e) {	
 if(e){
		// 正则表达试
		e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null
		// 重新赋值
		this.$nextTick(() => {
			   this.countnum = e
		});
	}
},

或者是

// 只能输入两位小数
	inputNumber(e) {
		//正则表达试
		 e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null
		
		 //重新赋值给input
		 this.$nextTick(() => {
		    this.countnum = e
		 })
	},

原文链接:https://blog.csdn.net/AAAXiaoApple/article/details/122566112

栏目分类
最近更新