如何在打开和关闭侦听器之前传递给vue-js-modal对话框?

问题描述:

对于我使用的对话窗口https://github.com/euvl/vue-js-modal。我需要在关闭对话框后执行一些代码,所以如何在打开和关闭侦听器之前通过对话框?如何在打开和关闭侦听器之前传递给vue-js-modal对话框?

变化:

我加@before-open="beforeOpen" @before-close="beforeClose"<v-dialog>和方法部分列出他们,但仍然无法正常工作

的index.html

<!DOCTYPE html> 
    <html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>{%=o.htmlWebpackPlugin.options.title || 'Undefended'%}</title> 
    </head> 
    <body> 
    <div id="app"> 
     <form id="form2" v-on:submit.prevent="login"> 
      <input type="email" v-model="signIn.email" placeholder="[email protected]"> 
      <input type="password" v-model="signIn.password" placeholder="Password"> 
      <input type="submit" value="Sign In"> 
     </form> 

     <v-dialog @before-open="beforeOpen" @before-close="beforeClose"/> 
    </div> 
    <script src="/dist/build.js"></script> 
    </body> 
    </html> 

main.js缩短版本

import VModal from 'vue-js-modal' 

Vue.use(VModal, {dialog: true}); 
new Vue({ 
    el: '#app', 
    data: { 
     signIn: { 
      email: '', 
      password: '' 
     }, 
    }, 

    methods: { 
     beforeOpen: function() { 
      console.log("open") 
     }, 
     beforeClose: function() { 
      console.log("close") 
     }, 

     login: function() { 
      fireAuth.signInWithEmailAndPassword(this.signIn.email, this.signIn.password) 
       .then((user) => { 
        if (!user.emailVerified) { 
         //-------------dialog-------------// 
         this.$modal.show('dialog', { 
          title: 'Alert!', 
          text: 'Please verify your email', 
          buttons: [{ 
           title: 'Send verification email', 
           handler:() => {} 
          }, {title: 'Close'}] 
         }); 
         //-------------dialog-------------// 
        } 
       }) 
     } 

    }, 
}); 
在这种情况下没有什么

写入

+0

请添加HTML模板 – imcvampire

+0

我只是用和它的作品不错 –

可以在v-modal事件设置功能控制台:

<v-dialog @before-open="beforeOpen" @before-close="beforeClose"/> 

,并且定义了两种方法:

methods: { 
    beforeOpen() { console.log('open') }, 
    beforeClose() { console.log('close') } 
} 
+0

OK,我'并添加'写这个'方法:{beforeOpen:function(){ console.log(“open”) }, beforeClose:function(){ console.log(“close”) },}'to main parent Vue instance, happend –

+0

你能分享我的完整代码吗?你可以使用jsfiddle! – imcvampire

+0

我刚更新了代码 –

@ imcvampire的答案是完美的,但是如果你有任何dou BTS和希望的例子那就是:

https://github.com/euvl/vue-js-modal/blob/master/demo/client_side_rendering/src/components/SizeModal.vue

在VUE-JS-模式。

感谢您使用插件。

v-dialog目前不支持监听。它是modal的一个非常薄的包装,更像是真正的例子。我认为针对您的问题的解决方案将只是直接使用模态及其所有功能。