今天在写代码的时候,爆出了一个问题,在我使用this.$router.push的时候,hash地址改变了,但是页面却不发生跳转。

地址从admin跳转到了login后,仍然没有发生改变

<van-button type="success" class="" @click="reset">重置</van-button>
<van-button type="primary" class="" @click="login">登录</van-button>
给它绑定一个事件:
reset(){
this.username = '';
this.password = '';
},
login(){
if(this.username === 'likaicheng' && this.password === '666666'){
// 1.存储token
localstorage.setitem('token','bearer xxxx')
// 2.跳转到后台主页
this.$router.push('/login' )
}else{
// 登录失败
localstorage.removeitem('token')
}
}将main.js的显示页面改为app.

加上<router-view>才能跳转页面,具体的做法是首先在app.vue中删除其他的代码,只加上router-view。

之后点击之后,页面发生改变了。

到此这篇关于vue中this.$router.push点了后hash地址改变了页面不跳转的文章就介绍到这了,更多相关vue this.$router.push页面不跳转内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论