Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

问一个VUE的页面跳转问题

使用VUE脚手架建立了几个组件,并在路由中设置了它们。

image

image

我现在想在my.vue中检测用户是否登录,如果没有登录就自动跳转到login.vue这个组件上。

我在my.vue文件中:

created:function(){
      //const that = this
      //const token = localStorage.getItem('xtoken')
      //if(token == ''){
         location.href = login
      //}

结果没有跳转到login这个组件上,而是直接跳转到首页(app_index)去了???

问题:
1.这个我应该怎么写,才能正确的跳转到login组件上去?
2.如果我Login登录界面也写到my这个组件上去,如果登录状态我就隐藏login的登录框;如果没有登录,则显示登录框,不显示下面MY组件上的内容?(类似于普通HTML页面上隐藏DIV)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
this.$router.push({
    path:'/login';
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...