1. 子组件中定义方法并通过defineExpose暴露出去
import { reactive, defineExpose } from "vue";
const state = reactive({
dataList: [],
});
const changeData = () => {
state.dataList.push(1);
}
defineExpose({
changeData,
});
2. 父组件通过ref调用子组件暴露的方法
<child ref="childRef"></child>
import {ref} from "vue";
const childRef = ref(null);
childRef.value.changeData();
vue2中通过$refs方法调用
标签:调用,const,defineExpose,Vue3,组件,changeData,ref From: https://www.cnblogs.com/lpkshuai/p/17176606.html