链接HREF上的V-Bind不起作用,而仅在生产中(NUXT静态站点)

发布于 2025-01-28 11:36:14 字数 1004 浏览 2 评论 0原文

我正在尝试将生成的链接绑定到按钮。该链接是根据URL中传递的参数生成的。该代码看起来像这样:

      <a :href="generated_link">
        <button
          type="button"
          class="button"
        >
          Go to Link
        </button>
      </a>

生成链接的代码:

mounted() {

let route_variables = {
  cmpid: this.$route.query.cmpid,
  utm_source: this.$route.query.utm_source,
};

if (route_variables["cmpid"] === undefined) {
  console.log(route_variables["cmpid"]);
  route_variables["cmpid"] = "2983928372983";
}

var newLink = "https://www.website/?";
for (const property in route_variables) {
  if (route_variables[property] != undefined) {
    newLink += property + "=" + route_variables[property] + "&";
  }
}
this.generated_link = newLink;
},

在开发中,链接被正确填充。当我向URL添加CMPID变量时,将其附加到预期的按钮链接上。但是,在部署中,即使我将其添加到URL时,CMPID变量始终设置为我已设置为默认值的值,即使URL中没有变量。我认为这是因为它在构建时间进行了评估。如果我只使用((generated_link}}打印页面上的链接,则可以正常工作。我尝试了一堆不同的解决方法来尝试获取A标签以渲染客户端以无效。任何帮助都将不胜感激。呢

I am trying to bind a generated link to a button. The link is generated based on parameters passed in the URL. The code roughly looks like this:

      <a :href="generated_link">
        <button
          type="button"
          class="button"
        >
          Go to Link
        </button>
      </a>

The code to generate the link:

mounted() {

let route_variables = {
  cmpid: this.$route.query.cmpid,
  utm_source: this.$route.query.utm_source,
};

if (route_variables["cmpid"] === undefined) {
  console.log(route_variables["cmpid"]);
  route_variables["cmpid"] = "2983928372983";
}

var newLink = "https://www.website/?";
for (const property in route_variables) {
  if (route_variables[property] != undefined) {
    newLink += property + "=" + route_variables[property] + "&";
  }
}
this.generated_link = newLink;
},

In development, the link is populated properly. When I add a cmpid variable to the URL then it is appended to the button link as expected. In deployment, however, the cmpid variable is always set to the value I have set as the default when there is no variable in the URL, even when I add it to the URL. I think that this is because it is being evaluated in build time. If I just use ((generated_link}} to print the link on the page it works fine. I have tried a bunch of different workarounds to try to get the a tag to render client-side to no avail. Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文