当前位置:网站首页>Amount input box, used for recharge and withdrawal

Amount input box, used for recharge and withdrawal

2022-04-23 17:49:00 Sanxiaochi 513

Encapsulate as a function , Hang up Vue On the prototype

//  Amount input 
function cash(e){
	let price = e.toString()
	//  When you enter the decimal point directly, it is converted to '0.'
	if(price.indexOf('.') == 0){
		price = price.replace(/[^$#$]/g,'0.')
	}
	//  First multiple 0 Turn into a 
	price = price.replace(/^0{1,}/g,'0')
	//  Convert consecutive decimal points into one 
	price = price.replace(/\.{2,}/g,'.')
	//  Only two decimal places 
	price = price.match(/^\d*\.?\d{0,2}/g)[0]
	return price
}
Vue.prototype.$cash = cash

Listen for input events in the input box

input(e){
    this.$nextTick(() => {
		this.cash = this.$cash(e)
	})
},

版权声明
本文为[Sanxiaochi 513]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230550325319.html