<template>
<div>
<el-input v-model="inputValue" @input="handleInput"></el-input>
</div>
</template>
<script>
export default {
data() {
return {
inputValue: ''
};
},
methods: {
handleInput(value) {
// 使用正则表达式检查输入值,只允许数字和特定符号
this.inputValue = value.replace(/[^\d+-]/g, '');
// 正则表达式 /[^\d+-]/g 只允许数字和加号减号,你可以根据你的需求调整这个正则表达式。
}
}
};
</script>