这种跳转方式类似于传统的a 标签实现跳转
<router-link to="./shop">Go Shop</router-link>
用的较多的是使用方法进行跳转然后实现页面之间的传参
<div @click="gohome">我要去home</div>
<script>
export default {
data() {
return {
id:5
};
},
methods: {
gohome() {
this.$router.push({
path: "/home",
query: {
id: this.id
}
});
}
},
};
</script>
接收参数页面 在域名就会看到域名带?id=5
<script>
export default {
data() {
return {};
},
methods:{
},
created(){ //生命周期里接收参数
this.id = this.$route.query.id,
console.log(this.id)
}
};
用法跟this.$router.push一样,但是跳转有区别。 前者跳转之后会向history栈添加一个记录,点击后退会返回到上一个页面。 后者跳转不会向history里面添加新的记录,点击返回,会跳转到上上一个页面。上一个记录是不存在的。
类似于window.history.go(n)。
// 在浏览器记录中前进一步,等同于 history.forward()
this.$router.go(1)
// 后退一步记录,等同于 history.back()
this.$router.go(-1)