vue3.2的项目中,子组件(ViewQuestionDetail.vue)传递2个方法给父组件(ShowQuestion.vue)。
用的是defineExpose。源代码如下:
```html
<template>
<el-dialog
title="题目详情"
v-model="state.visible"
width="400px"
>
<template #footer>
<span class="dialog-footer">
<el-button @click="state.visible = false">关 闭</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup>
import { reactive } from 'vue'
const props = defineProps({
question: Object,
});
const state = reactive({
visible: false
});
// 开启弹窗
const open = () => {
state.visible = true
};
// 关闭弹窗
const close = () => {
state.visible = false
};
// 将需要暴露出去的数据与方法都可以暴露出去
defineExpose({ open, close })
</script>
运行后出现:控制台提示:
```javascript
defineExpose is not defined at setup
尝试过度娘中的各种办法,包括升级node 和vue,都没用