new Vue({
el: '#app',
name:'test',
data() {
return {
myInt:123456,
}
},
methods: {
change () {
this.$nextTick(function(){
this.myInt = this.myInt.toString().replace(/[^\d]/g,'')
})
}
}
})
<div id="app">
myInt:{{myInt}}
<br>
请在下表单中继续输入字符串测试<br>
<input type='text' v-model="myInt" @input='change'>
</div>