VUE 监听watch 对象某个属性值变化
需求:如果想监听对象 form中 属性 type的变化:<script>export default{data(){return{form:{name:"",type:""}}}}</script>一、可以使用watch 结合 computedcomputed:{type(){
·
需求:如果想监听对象 form中 属性 type的变化:
<script>
export default{
data(){
return{
form:{
name:"",
type:""
}
}
}
}
</script>
一、可以使用watch
结合 computed
computed:{
type(){
return this.form.type
}
},
watch:{
type(val){
console.log(val)
}
}
二、使用 deep
watch:{
form:{
handler(newVal){
console.log(newVal)
},
deep:true
}
}
更多推荐
已为社区贡献25条内容
所有评论(0)