比如 :
<add-roles v-if="flag" :id="current_id" ></add-roles>
有个函数把flag 设置为true 子组件显示
look_role(id){
this.flag = true
this.current_id =id
},
子组件
props:["id"],
watch:{
'id':function(newVal,oldVal){
console.log("sdfsadf",newVal)
},
你会发现根本监听不到 id 的变化
这是因为v-if 会影响 子组件的生命周期 导致watch 不起作用
把 v-if 换成 v-show 就解决了。
网友评论