我有一个 vue 组件,它有很多道具,但遇到了一个小问题。这个 CTA 组件按钮可以有一个脚注作为道具,也可以包含一个链接,就像这个一样。即使它是一个字符串,是否可以向此链接添加点击事件(谷歌分析跟踪器)?
<CTA
title="Sign up for Savings"
sub-title="Learn about the different ways<br> to save.<sup>†</sup>"
:has-button="true"
button-text="Sign up"
button-href="/savings-and-support/savings"
:has-footnote="true"
footnote="<sup>†</sup>Restrictions apply. See <a @click='WHERE I WANT GA CLICK EVENT' href='/savings-and-support/savings#terms' style='text-decoration:underline'>eligibility requirements</a> for more information."
@click="$ga.event('navigation', 'click', 'barker')">
</CTA>
组件:
<template>
<div class="cta-column" :class="{ 'cta-column--one-item': oneColumn }">
<div class="icon">
<slot name="icon"></slot>
</div>
<div class="cta callout-row__cta-title">
<h2 v-html="title"></h2>
</div>
<div class="cta-sub-title">
<p v-html="subTitle"></p>
</div>
<template v-if="hasButton">
<router-link v-if="useRouterLink" :to="buttonHref" class="cta__button button" v-html="buttonText"> </router-link>
<a v-else :href="buttonHref" class="cta__button button" v-html="buttonText"> </a>
</template>
<div class="cta-footnote" v-if="hasFootnote">
<p class="footnote" v-html="footnote"></p>
</div>
</div>
</template>
<script>
export default {
name: 'CTA',
props: {
title: {
type: String,
required: true
},
subTitle: {
type: String,
required: false
},
hasButton: {
type: Boolean,
required: false
},
buttonText: {
type: String,
required: true
},
footnote: {
type: String,
required: false
},
hasFootnote: false,
oneColumn: false,
buttonHref: {
type: String,
required: true
},
useAnchor: {
type: Boolean,
default: false
}
},
}
</script>