调起数字键盘
<template>
<input :type="type" v-model="data" @focus="changeType(0)" @blur="changeType(1)" @input="change(data)" ref="input" />
</template>
<script>
export default {
data() {
return {
data: '',
type: 'number',
};
},
methods: {
changeType(type) {
this.type = type === 1 ? 'number' : 'text';
},
change(val) {
val = val.replace(/(^\s*)|(\s*$)/g, '');
if (!val) {
this.data = '';
return;
}
const reg = /[^\d.]/g;
val = val.replace(reg, '');
val = val.replace(/^\./g, '');
val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
this.data = val;
},
},
};
</script>