子组件
<script setup>
import { reactive, ref, toRefs } from "vue";
const alertDialog = ref(null);
const publicData = reactive({
type: 'center',
msgType: 'success',
msg: ''
})
const openDialog = (type,msg) => {
publicData.msgType = types
publicData.msg = msg
alertDialog.open()
}
defineExpose({
openDialog
})
</script>
父组件
<dialog ref='dialogref'></dialog>
<button @click='open'>按钮</button>
const dialogref = ref(null);
const open = ()=>{
dialogref.value.openDialog('error','内容')
}
使用父组件 调用 子组件defineExpose 暴露的方法时报错 TypeError: dialogref.value.openDialog is not a function。用的是最新的hbuilder-x 3.6.4 和uniapp vue3 项目。
DCloud_UNI_WZF
onMounted 以后再获取试试
2022-12-30 14:56