Vue3 子组件传给父组件(方法) 弹窗案列

编程入门 行业动态 更新时间:2024-10-11 21:23:04

Vue3 子<a href=https://www.elefans.com/category/jswz/34/1771375.html style=组件传给父组件(方法) 弹窗案列"/>

Vue3 子组件传给父组件(方法) 弹窗案列

父组件

弹窗绑定 ref="menuDialogRef"

html内容

<JsonForm ref="menuDialogRef" />

 js中代码编写

const JsonForm = defineAsyncComponent(()=>import('/@/views/main/drive/dialog.vue'))const menuDialogRef = ref(); //修改组件弹窗//父组件点击事件
const onOpenEditRole = () => {//接收子组件的弹窗openDialog()为子组件方法menuDialogRef.value.openDialog()};

子组件

 主要暴露方法openDialog ()弹窗逻辑

暴露变量:

defineExpose({

  openDialog,

});

<template><div class="system-role-dialog-container"><el-dialog :title="title" v-model="isShowDialog" width="30%" draggable><div>123</div><template #footer><span class="dialog-footer"><el-button size="default">取 消</el-button><el-button type="primary" size="default">确定</el-button></span></template></el-dialog></div>
</template><script setup lang="ts" name="systemRoleDialog">
import { reactive, ref } from 'vue';const title = ref()
const isShowDialog = ref(false)
// 打开弹窗
const openDialog = () => {title.value = '修改表单值'isShowDialog.value = true
}
// 暴露变量
defineExpose({openDialog,
});
</script><style scoped lang="scss"></style>

更多推荐

Vue3 子组件传给父组件(方法) 弹窗案列

本文发布于:2023-12-06 21:07:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1668921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   方法   弹窗案列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!