<template>
<view>
<input v-model="money" type="number" @input="check" placeholder="金额(元)" />
</view>
</template>
<script>
export default {
data() {
return {
money:''
}
},
methods: {
check: function(e) {
//正则表达试
e.target.value = (e.target.value.match(/^\d*(\.?\d{0,2})/g)[0]) || null
//重新赋值给input
this.$nextTick(() => {
this.money= e.target.value
})
},
},
}
</script>
<style>
</style>
记录一次就少加班一次,哈哈哈~~~