简体   繁体   English

Can't Run Vue Js Method from SweetAlert2 Pop up

[英]Can't Run Vue Js Method from SweetAlert2 Pop up

I have this vue js app with a pop up using SweetAlert2.我有一个使用 SweetAlert2 弹出的 vue js 应用程序。 There a link in the pop up message that needs to call a vue js method.弹出消息中有一个链接需要调用vue js方法。 But, i can't get it to work.但是,我无法让它工作。

<template>
    <button @click="popModal()">Alert</button>
</template>

export default {
data(){
    return{
        popMessage: "<h5>Title</h5> 
        <p>I'm trying to call a vue js method on this link <a href='https://www.google.com' target='_blank' id='popLink' @click='run Method()'>google.com</a>. </p>"
     }
},
methods: {
  popModal(){
      this.$fire({
          html: message,
          showCancelButton: false
       })
  },
  runMethod(){
     console.log("Link in pop up!");
  }
}
}

I'm guessing:我正在猜测:

  • you're using Vue 2你正在使用 Vue 2
  • you've installed SweetAlert2 correctly and it adds a global method called $fire to your app.您已经正确安装了 SweetAlert2,它会在您的应用程序中添加一个名为$fire的全局方法。

If the above guesses are true, there are only two problems:如果以上猜测都是真的,那么只有两个问题:

  • popMessage in data contains line breaks, which break compilation. data中的popMessage包含换行符,这会中断编译。 Either replace the double quotes (") with back-ticks (`), which will preserve the line breaks, or place each line inside double quotes and concatenate them.将双引号 (") 替换为反引号 (`),这将保留换行符,或者将每行放在双引号内并将它们连接起来。
  • message is undefined . message undefined Did you mean this.popMessage ?你的意思是this.popMessage吗?
this.$fire({
  html: this.popMessage,
  showCancelButton: false
})

Side notes :旁注

  • nobody should have to guess anything when answering your questions;在回答您的问题时,任何人都不应该猜测任何事情; in the future, please provide all relevant details将来,请提供所有相关详细信息
  • the browser console is your friend.浏览器控制台是您的朋友。
    It will help you figure out some errors on your own and it will also help you write better questions on StackOverflow.它会帮助你自己找出一些错误,也会帮助你在 StackOverflow 上写出更好的问题。 Providing a relevant console error/warning inside the question is likely to get you better answers, faster.在问题中提供相关的控制台错误/警告可能会更快地为您提供更好的答案。

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

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