vue2.0 watch监听
1、单个变量可以用浅监听,如是对象就用深度监听了
<template lang="html">
<div>
<input type="text" v-model="username">
<input type="text" v-model="person.name">
</div>
</template>
<script>
export default {
data () {
return {
username: 'vhen',
person: {
name: ''
}
}
},
watch: {
username () { //浅监听
this.username = this.username.replace(/[\u4e00-\u9fa5]/g, '');
},
person: { //深度监听
handler (newValue, oldValue) {
newValue.name = newValue.name.replace(/[\u4e00-\u9fa5]/g, '');
},
deep: true
}
}
}
</script>
<style lang="css">
</style>

浙公网安备 33010602011771号