山林小树 2019-06-03 21:13 采纳率: 20%
浏览 1877
已采纳

如果利用vue处理json串

html前端表单提交到某接口后(javaweb的接口),返回了字符串

{"Login":true}

请问如果利用vue处理该返回结果,实现成功登录的页面跳转?

  • 写回答

2条回答 默认 最新

  • zhenyu-s5 2019-06-04 08:49
    关注

    首先在你的ajax回调函数中判断Login,根据规定好的内容提示不同信息,然后在验证成功后
    进入其他页面this.$router.push('/index');注意this的指向。

    this.$axios.post(`${this.sIP}/users`, this.loginForm).then((res) => {
                  //console.log(res.data)
                  if (res.data == '用户不存在' || res.data == '密码错误' || res.data == 'err') {
                    this.$message.error({
                      duration: 500,
                      showClose: true,
                      message: res.data,
                      type: 'error'
                    })
                  }  else {
                    this.userToken = res.data.token;
                    //存储token
                    localStorage.setItem("token", res.data.token);
                    //解析token
                    let users = jwtDecode(res.data.token);
                    this.$store.dispatch('setisAuthenicated', !this.isEmpty(users));
                    this.$store.dispatch('setUsers', users);
                    //console.log(users)
                    this.$message({
                      showClose: true,
                      message: '登录成功',
                      type: 'success'
                    });
                    this.$router.push('/index');
                  }
                })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?