It looks like you're trying to call a method on a Vue 3 component's vnode, which is created using the h render function. To achieve this, you can follow these steps:
- First, create a Vue component with a method that you want to call. For this example, let's create a
MsgText2 component with a updateText method:
// MsgText2.vue
<template>
<div>
<p ref="text2">{{ text }}</p>
</div>
</template>
<script>
export default {
props: ['text'],
methods: {
updateText(newText) {
this.$refs.text2.innerHTML = newText;
},
},
};
</script>
- In your main Vue component, import the
MsgText2 component and call the updateText method on the created vnode:
// YourMainComponent.vue
<template>
<div id="app">
<button @click="updateText">Update Text</button>
<MsgText2 ref="msgText2" :text="initialText" />
</div>
</template>
<script>
import MsgText2 from './MsgText2.vue';
export default {
components: { MsgText2 },
data() {
return {
initialText: 'Initial text',
};
},
setup() {
const msgText2 = ref(null);
async function updateText() {
const newText = 'New text';
const nodeRoot = document.createElement("div");
const container = document.getElementById('robot_message_container_id');
container?.appendChild(nodeRoot);
const vnode = h(MsgText2, { ref: msgText2 }, []);
container?.appendChild(vnode.elm);
// Call the method on the created vnode
msgText2.value.updateText(newText);
}
return {
updateText,
};
},
};
</script>
In this example, we create a MsgText2 component with a updateText method that updates the text inside the text2 element. We then create a new vnode using the h render function and call the updateText method on the vnode's instance by accessing msgText2.value.updateText.