<template> <view class="richScanBox width100Percent"> <input type="number" v-model="form.money" @input="inputChange" placeholder="请询问服务员后输入" placeholder-style="font-size: 34rpx;color: #CCCCCC;" /> </view> </template> <script> export default { components: { }, data() { return { form: { money: '', } } }, // 侦听器 watch: { }, // 计算属性 computed: { }, // 页面加载 onLoad(e) { }, // 页面显示 onShow() { }, // 方法 methods: { // 计算金额 inputChange(e) { this.$nextTick(() => { let val = e.target.value.toString(); val = val.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符 val = val.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的 val = val.replace(/^0+\./g, '0.'); val = val.match(/^0+[1-9]+/) ? val = val.replace(/^0+/g, '') : val val = (val.match(/^\d*(\.?\d{0,2})/g)[0]) || '' if (val.includes(".")) { let numDian = val.toString().split(".")[1].length; if (numDian === 2) { this.form.money = val.length; } } else { // this.moneyMaxLeng = 8; } this.form.money = val; }); }, }, // 页面隐藏 onHide() { }, // 页面卸载 onUnload() { }, // 触发下拉刷新 onPullDownRefresh() { }, // 页面上拉触底事件的处理函数 onReachBottom() { }, } </script> <style lang="scss" scoped> .richScanBox { height: 100vh; } </style>