为了账号安全,请及时绑定邮箱和手机立即绑定

添加谷歌分析事件后,vue 点击事件被破坏?

添加谷歌分析事件后,vue 点击事件被破坏?

开满天机 2023-08-18 14:01:05
我在 vue 中的链接上有一个点击事件,该链接启动了一个模式,该模式有一个链接将用户引导到另一个网站。一切都按预期工作,直到我刚刚添加了谷歌分析点击事件。现在模式打开,但到另一个站点的链接只是返回到主页 /root。有没有办法在不中断的情况下调用链接上的两个点击事件?启动模式并链接出的链接:             <a              href="https://www.linkout.com"              rel="noopener"              @click.prevent="                openInterstitial;                $ga.event('link', 'click', 'ISI_link');              "              target="_blank"              >www.linkout.com</a            >mixin method:Vue.mixin({  methods: {      openInterstitial(event) {        if (event) {          event.preventDefault();          this.$store.commit('modals/setInterstitialHref', event.target.href);        }        this.$store.commit('modals/setShowInterstitial', true);      }    }  });店铺export const state = () => ({  interstitial: {    show: false,    href: ''  }});export const mutations = {  setShowInterstitial(state, boolean) {    state.interstitial.show = boolean;  },  setInterstitialHref(state, string) {    state.interstitial.href = string;  }};
查看完整描述

1 回答

?
炎炎设计

TA贡献1808条经验 获得超4个赞

我重现了您的问题,似乎您的openInterstitial方法根本没有被调用。问题是您使用该方法来访问事件数据(不带括号的用法)。因此,你不能像以前那样链接它们,它不会被执行。如果您使用单个处理程序,则只能省略括号。

您可以做的是使用带括号的方法并使用$event( Docs ) 传递事件数据。

@click.prevent="
  openInterstitial($event);
  $ga.event('link', 'click', 'ISI_link');
"

这样您就可以访问事件数据并链接多个方法。希望能解决您的问题!



查看完整回答
反对 回复 2023-08-18
  • 1 回答
  • 0 关注
  • 59 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信