v-if无法获取this.$refs,真正有效的解决方法。vue不可以直接修改props值。
v-if无法获取this.$refs,真正有效的解决方法。vue不可以直接修改props值。
·
两个常规解决方法和一个我最喜欢用的方法,解决v-if无法获取this.$refs。
一:
this.$nextTick(()=>{
console.log(this.$refs)
})
二:
v-if改为v-show
三(我最喜欢的方法):
visible是父组件通过props传来的值,因为vue提示无法直接修改props,因此用watch监听visible,并用visible2替换。
watch:{
visible(i1,i2){
this.visible2 = i1
if(i1){
this.init()
}
},
},
methods: {
init(){
this.$nextTick(()=>{
if (this.type == 1){
this.$refs.graphNode.init()
}else if (this.type == 2){
this.$refs.graphLink.init()
}
})
}
}
更多推荐
已为社区贡献2条内容
所有评论(0)