javascript - Vue:@click 上 :to 属性的奇怪行为
问题描述
我有这个对象:
标签.vue:
<template>
<router-link :to="getTo"
custom v-slot="{ navigate }">
<div role="link" @click="navigate">
{{text}}</div>
</router-link>
</template>
<script>
export default {
props: {
text: {
type: String
},
date: {
type: String
},
link: {
type: String,
}
},
created() {
console.log("this link: " + this.link);
},
computed: {
getTo: function() {
console.log("text: " + this.text);
console.log("link: " + "hashtag/" + this.text);
return "hashtag/" + this.text;
}
}
}
</script>
并在HashtagsList.vue中使用它:
<template>
<div>
<Hashtag text="test1"/>
<Hashtag text="test2"/>
<Hashtag text="test3"/>
<Hashtag text="test4"/>
<Hashtag text="test5"/>
</div>
</template>
但是,当我在位于
http://localhost:8080/hashtag/sometag
它去
http://localhost:8080/hashtag/hashtag/sometag
代替
http://localhost:8080/hashtag/sometag
我如何解决它?
http://localhost:8080/hashtag/test2
解决方案
您可以尝试在您的路线前使用“/”以使其成为绝对路线,并且 vue 不会连接该路线。
"/hastag/" + this.text
推荐阅读
- node.js - 如何将套接字与用户关联?
- video-streaming - 视频处理 - 离线与在线
- c# - 将数据发送到另一个用户控件内的用户控件
- javascript - 通过父组件的onClick更新组件状态
- android - Android模拟器位置模拟不起作用
- sql - T-sql SmallDateTime 添加时间过去的日期 23:30
- iterm2 - 为什么我在 iTerm2 终端中看不到彩色文本(只有黑色和白色)?
- java - 是否有可能在(!)初始化之后加载带有插入的 SQL 文件?
- c# - 如何测试 dotnet-core WCF 客户端的 XML 反序列化?
- java - PrintWriter 构造函数