<template>
<div>Vue使用watch监听一个对象中的属性的实现方法</div>
</template>
<!-- 方法 1 -->
<script>
export default {
data(){
return{
obj:{
show: true
}
}
},
methods:{
},
watch:{
'obj.show':{
handler:function(newVal,oldVal){
// todo 想要做的事
}
}
}
}
</script>
<!-- 方法 2 -->
<script>
export default {
data(){
return{
obj:{
show: true
}
}
},
methods:{
},
computed: {
newVal: function(){
return this.obj.show
}
},
watch:{
newVal:{
watchFun:function(){
// todo 想要做的事
}
}
}
}
</script>
<style lang="scss" scoped></style>
Vue使用watch监听一个对象中的属性的实现方法
最新推荐文章于 2023-08-27 11:32:40 发布