Solve the problem: automatically fall back to oldValue when the user enters other characters
<template>
<Input placeholder="用户Id" search enter-button v-model="userId" />
</template>
<script>
export default {
data() {
return {
userId: ''
}
},
watch: {
userId(newValue, oldValue) {
if (!Number(newValue)) {
this.$nextTick(() => {
this.userId = oldValue
})
}
}
}
}
</script>
After reading the source code, if you don’t write $nextTick, you can’t change it successfully. For the specific reason, you can read his source code to get it. Here we only give you the solution