【发布时间】:2019-04-24 15:14:42
【问题描述】:
我像这样创建 Vue/Vuetify 组件:
let item = this.$createElement(ComponentName, {
props: {
displayField: this.displayField,
valueField: this.valueField,
childrenField: this.childrenField,
level: this.level + 1,
checkboxes: this.checkboxes,
items: child,
parentNode: this,
root: this.root
}
});
我需要的是获取项目的componentInstance 属性。如果我这样做:
console.log(item.componentInstance);
console.log(item);
我看到item.componentInstance 是undefined。但是,当我在控制台中调查item 时,我看到它有这个componentInstance 属性,而不是undefined。下面是这两条命令的截图:
那么,这有什么问题呢?如何以编程方式访问此componentInstance?
【问题讨论】:
-
试试
setTimeout(() => console.log(item.componentInstance), 150)还是不确定吗? -
@Dani R. 我查过了。它是未定义的。但我不想这样。它看起来像一个肮脏的黑客。
-
确实如此,我不会推荐它。但是创建实例需要时间。
标签: javascript vue.js vuetify.js