The vue3 Composition API parent component calls the function of the child component through ref

I defined an undo undo function in the setup of the child component
insert image description here
and then added ref to the child component in the parent component

<CanvaBoard ref="childComponentRef"/>

Then write this in the setup of the parent component

const childComponentRef = ref(null)
const reFundo = function() {
    
    
    childComponentRef.value.undo();
}

insert image description here
Anyway, I couldn’t find this undo function,
and finally found a solution later
. Add it at the end of the setup of the subcomponent

defineExpose({
    
    
  undo
});

It would be nice to expose the undo function. It’s quite weird, but it’s a lot of insight.

defineExpose does not need to introduce any dependencies

Guess you like

Origin blog.csdn.net/weixin_45966674/article/details/131109665