vue watch关于对象内的属性监听
vue可以通过watch监听data内数据的变化。通常写法是:
data:{
a:100
},
watch:{
a(newval,oldVal){
//做点什么。。。
console.log(newval,oldVal)
}
}
vue监听整个对象,如下:
•deep:true深度监测
data:{
return{
msg:{
name:'hahah',
color:'red'
}
}
}
watch:{
msg:{
handler(newValue,oldValue){
//做点什么。。。
console.log(newValue)
},
deep:true
}
如果监听对象内的某一具体属性,可以通过computed做中间层来实现:
computed:{
name(){
returnthis.msg.name
}
},
watch:{
name(newValue,oldValue){
//做点什么。。。
console.log(newval,oldVal)
}
}
总结
以上所述是小编给大家介绍的vuewatch关于对象内的属性监听的相关知识,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!