sourcetip

Vuex 작업 - Axios 반환 오류

fileupload 2023. 6. 22. 22:09
반응형

Vuex 작업 - Axios 반환 오류

Vuex 작업 - Axios 반환 오류입니다.

약속이 올바른 값을 반환하지 않는 내가 무엇을 잘못하고 있습니까?

누군가가 이 의심을 도울 수 있습니다.

서버 뒤에 오류 메시지를 표시하고 싶습니다.

지금부터 관심을 가져주셔서 정말 감사합니다.감사해요.

요소

<q-form
                @submit="onSubmit"
                @reset="onReset"
              >
                <q-input outlined v-model="username" label="User" />
                <br>
                <q-input outlined v-model="password" type="password" label="Pass" />
                <br>
                <q-btn unelevated  type="submit" color="primary full-width" label="Enter" />
              </q-form>

    methods: {
...mapActions('auth', ['login']),
onSubmit () {
          this.login({ 'username': this.username, 'password': this.password }).then(obj => {
            console.log(obj)
          }).catch(obj => {
            console.log(obj)
          })
        }
}

function login ({ commit, state, getters }, data) {
  return axios.post(`/api/token`, {
    username: data.username,
    password: data.password
  })
    .then(response => {
      commit('setToken', response.data)
    })
    .catch(error => {
      return error
    })
}

POST http://localhost/api/token 400(잘못된 요청)

함수를 메서드 개체에 직접 붙여넣는 대신 정의해야 합니다.

methods: {
  ...mapActions('auth', ['login']),
  myLogin() {
    this.login({ 'username': this.username, 'password': this.password }).then(obj => {
      console.log(obj)
    }).catch(obj => {
      this.error = obj;
    })
  },
}

또한 동일한 이름의 작업을 매핑하고 있습니다.login그래서 당신은 당신의 지역적인 방법을 다른 이름으로 바꿔야 할 것입니다, 그래서 제가 그것을 부른 것입니다.myLogin.

작성data라는 속성error및 사용:{{ error }}오류를 표시하려는 구성 요소에 있습니다.

언급URL : https://stackoverflow.com/questions/55989064/vuex-action-returning-axios-return-error

반응형