Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

this.$route.query 获取不到值

具体情况是这样的,在当前的导航栏页面中,我可以获取到由登陆页面传过来的username

  mounted () {
    this.username = this.$route.query.username
    console.log("接收到的username:"+this.username)
    // 正常输出
  }

当我点击导航栏从而切换页面时,我想把这个username传到其它页面上去

    handleSelect(key, keyPath){
      console.log(this.username+" key:"+key)
      // 可以正常打印出username和目标路径
      this.$router.push({
        path:key,
        query:{username:this.username}
      })
    }

页面可以正常跳转,但是在目标页面中获取不到username

        mounted(){
          var username = this.$route.query.username;
          console.log("用接收到的username:"+username)
          // 结果为undefined
        }

前面我没说关于地址栏的情况
当我处于登陆界面时

http://localhost
:8080/login

十分正常,当我登陆以后也就是执行了第一次传输username之后,进入到主页中,地址栏显示为

http://localhost
:8080/index?username=root

到这里也十分正常,页面执行了上面的第一段代码,成功接受到username,然后点击导航栏切换页面后,执行上面的第二段代码,此时要跳转到下一个页面

http://localhost
:8080/test

此时地址上并没有附带参数


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

1 Reply

0 votes
by (71.8m points)

我用你的代码试了试,能获取到呀。。。奇怪


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...