vue输入框禁止输入非数字(兼容IE火狐)
2020-05-22 本文已影响0人
祈澈菇凉
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<Input v-model="testInput"></Input>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
testInput: ''
}
},
watch: {
testInput(v) {
if (String(v).indexOf('.') > 0) this.testInput = '';
this.$nextTick(() => { //这里
this.testInput = String(v).replace(/\D/g, '');
});
},
}
})
</script>
</body>
</html>