简体   繁体   English

Vue & Quasar - 共享自定义对话框组件

[英]Vue & Quasar - Sharing a custom dialog component

I've looked at Reuse Quasar Dialog plugin with custom component on another component that does not have any answers and I have close to the same question but I have structured code a bit different.在另一个没有任何答案的组件上查看了Reuse Quasar Dialog plugin with custom component ,我已经接近相同的问题,但我的结构化代码有点不同。 On my parent form I have在我的父母表格上,我有

        <q-dialog prevent-close v-model="showProfileForm" class="profileDialog">
        <profile-dialog></profile-dialog>
        </q-dialog> 

and my profile-dialog is a form that is a simple template我的个人资料对话框是一个表单,它是一个简单的模板

         <template> 
            <q-stepper

It seems that if I wrap the component on the parent page the dialog will open BUT I cannot pass in似乎如果我将组件包装在父页面上,对话框将打开但我无法传入

      prevent-close 

or add a或添加一个

       @hide

I need to know when the dialog form is closed to save changes or prevent closing unless a button is clicked.我需要知道对话框何时关闭以保存更改或防止关闭,除非单击按钮。 Even adding the prevent-close in the parent does not work即使在父级中添加防止关闭也不起作用

   <q-dialog prevent-close v-model="showProfileForm" class="profileDialog">
   <profile-dialog></profile-dialog>
   </q-dialog> 

If I create the form inside a q-dialog, so it becomes a dialog inside a dialog and set the v-modal to true when it closes the parent form still has the slight gray overlay until the page is clicked and the form will not open a second time如果我在 q-dialog 中创建表单,那么它就变成了对话框中的对话框,并在关闭时将 v-modal 设置为 true,父表单仍然有轻微的灰色覆盖,直到单击页面并且表单将无法打开第二次

You can use the emit event in profile dialog for pass event so that you know that form is submitted or not and use persistent so that User cannot dismiss Dialog if clicking outside of it or hitting ESC key;您可以使用emit在配置文件对话框的事件通事件,让你知道表单提交与否和使用持久性,使用户无法关闭对话框,如果点击它外面或者按ESC键; Also, an app route change won't dismiss it.此外,应用程序路由更改不会关闭它。

   <q-btn v-if="step == 4" @click="FinishClick" color="primary" label="Finish"/>



    methods: {
        FinishClick() {
            alert("Finish Click From Profile Dialog");
            this.$emit("profile_dialog_emmit",{'MSG':'TestData'})
        }
    }

  <profile-dialog @profile_dialog_emmit="my_fun($event)"></profile-dialog>

In Parent Component.在父组件中。

methods:{
    my_fun(data){
        console.log("Assad");
        alert("From Index Check Console for Data");
        console.log(data)
        this.showProfileForm=false;
    }
  }

Demo - https://codesandbox.io/s/clever-kilby-qf1gz演示 - https://codesandbox.io/s/clever-kilby-qf1gz

Go to the final step and click on finish will trigger the event and you can see an alert from the parent component and check the console for data displayed from the parent component.转到最后一步,单击完成将触发事件,您可以看到来自父组件的警报,并检查控制台以获取父组件显示的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM