Vue3 使用 h函数创建组件并使用 组件作为节点时,如何获取该节点的 ref
Vue3 使用 h函数创建组件并使用 组件作为节点时,如何获取该节点的 ref
import {VxeTable, VxeColumn, VxeToolbar, VxeTableInstance, VxeToolbarInstance} from 'vxe-table'
export default defineComponent({
setup(props: any, {slots}: any) {
const xTable1 = ref<VxeTableInstance>();
const xToolbar1 = ref<VxeToolbarInstance>();
const divRef = ref();
const componentTable = h(VxeTable, {
ref: xTable1,
size: "mini",
border: true,
}, []);
const componentToolbar = h(VxeToolbar, {
ref: xToolbar1,
print: true,
custom: true
});
onMounted(() => {
console.log(xToolbar1)
console.log(divRef)
});
return () => h('div', {
ref: divRef
}, [ componentToolbar, componentTable])
},
});
在上述代码中, 最终 console.log 打印的对象xToolbar1的 value 值始终是 undefined,但 divRef 是可以获取到dom节点的
那么 h 函数使用 第三方组件渲染时,需要使用什么方式可以获取到该 组件的 ref 值