Skip to content

如何获取 content 的实例? #10

Description

@inCBle

大佬你好,我想请问一下我该如何获取 content 的组件实例?

我的需求是在一个复杂弹窗组件中,我希望按模块将同模块的业务子需求统一内聚到弹窗 content 组件中,如示例我的提交按钮是使用 dialog 的插槽配置渲染,所以需要获取 contentRef 调用组件实例的方法。但是实际使用时,contentRef.value 是 undefined ,大佬有解决方案不,或者例如这种需求是否有更好的设计建议。

示例:

<template>
  <div class="flex justify-center items-center">
    <el-button @click="openDialog">打开弹窗</el-button>
  </div>
</template>

<script setup name="base-example" lang="tsx">
import { useDialog } from "@vue-cmd/element-plus";
import DialogContent from "./shared/DialogContent.vue";
import { ref } from "vue";

const CommandDialog = useDialog();
const contentRef = ref();

const handlePreview = () => {
  console.log(contentRef.value); // 打印 undefined
};

const openDialog = () => {
  CommandDialog(<DialogContent ref={contentRef} />, {
    title: "hello world",
    width: "90%",
    slots: {
      footer: () => (
        <el-button onClick={handlePreview}>查看 contentRef </el-button>
      ),
    },
  });
};
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions