早睡早起,方能养生
Sleep early rise early, way to keep healthy

vue跳转页面,切换路由

super
2023-03-12 11:41
views 2042

1)

 

location.href = "/Home";

 

2)

 

常规:

 

<router-link to="Home">首页</router-link>

 

进阶:

 

<router-link :to="Home">首页</router-link>

 

data() {
	return {
		Home: ''
	}
},
created() {
    let token = localStorage.getItem('token');
    if (token) {
		this.Home = 'Home';
    } else {
		this.Home = 'Login';
    }
},

 

 

3)

 

this.$router.push({ path:'/Home' })

 

拓展:

 

1)返回上一页

 

this.$router.go(-1)


分享
0 条讨论
top