<template>
<div>
<input type="text" v-model="value" @input="inputFn" />
</div>
</template>
<script>
export default {
data() {
return {
value: "",
};
},
methods: {
inputFn() {
this.value = this.value
.replace(/[^/0-9.]/g, "")
.replace(/(\.d+)\.+/g, "$1")
.replace(/(\..*)\./g, "$1")
.match(/^\d*(\.?\d{0,2})/g)[0] || "";
},
},
};
</script>
<style>
</style>
input输入框只能输入小数和整数,并且小数只保留小数点后两位
最新推荐文章于 2024-07-31 14:35:30 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)