此软键盘用的vant
<template>
<van-number-keyboard v-model="inputPrice" :extra-key="['00', '.']" :show="showKeyboard" maxlength="16" @blur="showKeyboard = false" theme="custom" close-button-text="完成" />
</template>
<script>
export default {
name:'',
data(){
inputPrice:'', // 输入金额
}
},
watch:{
// 校验输入金额 最多两位小数 最多一个小数点
inputPrice: {
handler: function (newVal, oldVal) {
let n = (newVal.split('.')).length - 1;
this.inputPrice = this.inputPrice.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
if (n > 1 || (n == 1 && newVal.length == 1)) {
this.inputPrice = oldVal
}
},
},
}
</script>
<style type="text/less" lang="less" scoped>
</style>