icool_老羊
icool_老羊
  • 发布:2022-10-24 15:15
  • 更新:2023-03-10 11:20
  • 阅读:638

关于vue3-defineExpose + ref的问题

分类:uni-app

子组件

<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 项目。

2022-10-24 15:15 负责人:无 分享
已邀请:
icool_老羊

icool_老羊 (作者)

大佬们帮忙看看,是哪里写的不对吗

竹林遇风

竹林遇风

我也遇到这个问题,后来怎么解决的

要回复问题请先登录注册