关于vue的$refs出现undefined

问题描述:

dom结构有

<el-row v-if='aComplete && bComplete'>
<el-row ref="myRef"></el-row>
</el-row>

你在aComplete的事件后增加了 

this.$nextTick(() => {
    // DOM 更新了
    console.log("0000")
    console.log(this.$refs["staffFormRef"])
    this.$refs["staffFormRef"].clearValidate();
});

仍然会出现undefined(因为bComplet可能还未是true)

解决方法:

1 v-if更改为 v-show

2 确保 a 和 b 都是complete再获取该对象的操作

v-if 会导致 ref 某一个dom节点找不到

I can see a bigger world.
原文地址:https://www.cnblogs.com/xuweiqiang/p/14261406.html