链接HREF上的V-Bind不起作用,而仅在生产中(NUXT静态站点)
我正在尝试将生成的链接绑定到按钮。该链接是根据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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论