使用的 iView Select
组件,组件有一个方法: clearSingleSelect()
. 调用方法为 this.$refs.nameSelect.clearSingleSelect()
, 经过测试正常使用是没问题的。现在想要在 render
函数里调用, 一直获取不到 this.$refs.nameSelect
,报 undefined
相关代码
h('Select', {
ref: 'nameSelect',
props: {
transfer: true,
clearable: true,
},
on: {
'on-change': (value) => {
if (value === 'CLEAR') {
this.$refs.nameSelect.clearSingleSelect()
}
},
},
}, this.assembleOptions(h, this.options))
怎样在 Render function 里面使用 $refs 呢?
补充:
this
指向是没问题的,log(this.$refs)
能看到其他直接在 template
里的写好的组件的 ref
. 感觉问题应该是当 render
函数把 Select
组件渲染以后,this.$refs
没有动态更新。 所以报 undefined
,有没有手动去更新 this.$refs
的方法,或者直接获取到 render
函数渲染出来的实例的方法?
你估计用的h是组件返回的 这个是vnode作用域实在 h所在的组件 你可以把h改成 this.$createElement
