(Vue.js)错误:axios未定义'token'(no-undef)

时间:2020-02-19 17:59:17

标签: vue.js axios token

strtime('next hour')

执行此代码时发生错误。

错误:未定义“令牌”(无undef)

登录时的响应值为

axios.post(`${this.url}/auth/login`, {
    email: this.email,
    pw: this.pw
  })
  .then( response => { 
    if (response.status === 200) {
      this.$swal('환영합니다!','로그인에 성공하였습니다.','success')
      this.$store.state.login = true
      console.log(response.data.data.x-access-token)
      this.$router.push({ name: 'home' })
    }
  })
  .catch( error => {
    if (error.response.status === 401 || error.response.status === 400) {
      this.$swal('오류','이메일 또는 비밀번호가 올바르지 않습니다.','error')
    }
  })

但是我无法使用data: is_student: true is_worker: false x-access-token: "token" message: "로그인 성공." status: 200 访问令牌。
我该怎么办?

1 个答案:

答案 0 :(得分:0)

您必须使用:response.data.data['x-access-token']