반응형
Vuex 디스패치가 반환되지 않음
다음 코드를 가지고 있다.
signin(context, payload, resolve) {
console.log("SIGNIN action")
const aemail = payload.locmail
const apassw = payload.locpass
backend.get("api/auth/signin", {
headers: {
'planck': 'FRESH'
},
crossDomain: true,
params: {
password: apassw,
email: aemail
}
}).then(function(ret) {
console.log("SENT")
if (ret.data.auth === 'TRUE') {
context.commit('authenticate', ret.data.planck)
state.isAuthenticated = true
} else {
state.isAuthenticated = false
}
console.log(ret)
return Promise.resolve(ret)
});
}
구성 요소에서 호출하면:
this.$store.dispatch('signin', {
locmail,
locpass
}).then(ret => {
console.log(ret);
});
그런 다음 콘솔 로그 인쇄undefined
내가 여기서 뭘 잘못하고 있는 거지?설명서에서 나는 다음을 사용해야 한다고 읽었다.resolve()
하지만 그게 함수가 아니라는 오류를 범하게 돼
리턴 더backend
을 약속하다signin
액션
signin(context, payload) {
// ...
// The action needs to return a Promise
return backend.get("api/auth/signin", {
/* ...*/
}).then(function(ret) {
/* ... */
});
}
또, 변신을 하고 있는 것 같다.state
행동의 대상이며 이는 돌연변이로 제한되어야 한다.
개발 중에 엄격한 모드를 사용하고 있다면 이에 대한 경고를 볼 수 있을 것이다.
너는 그 약속을 지키지 않을 것이다.변경하기signin()
@Emile Bergeron이 제안한 대로 여기에 기능한다.
signin(context, payload) {
console.log("SIGNIN action")
const aemail = payload.locmail
const apassw = payload.locpass
return backend.get("api/auth/signin", {
headers: {
'planck': 'FRESH'
},
crossDomain: true,
params: {
password: apassw,
email: aemail
}
}).then(function(ret) {
console.log("SENT")
if (ret.data.auth === 'TRUE') {
context.commit('authenticate', ret.data.planck)
state.isAuthenticated = true
} else {
state.isAuthenticated = false
}
console.log(ret)
return Promise.resolve(ret)
});
}
참조URL: https://stackoverflow.com/questions/49710481/vuex-dispatch-doesnt-return
반응형
'Programing' 카테고리의 다른 글
malloc는 gcc에서 값을 0으로 초기화하는 이유는? (0) | 2022.05.02 |
---|---|
변환 장치의 일부에 대해서만 GCC 경고를 선택적으로 비활성화 (0) | 2022.05.02 |
C에서 char 배열을 복사하는 방법? (0) | 2022.04.29 |
ConcurrentHashMap 대 동기화된 해시맵 (0) | 2022.04.29 |
현재 C 또는 C++ 표준 문서는 어디에서 찾을 수 있는가? (0) | 2022.04.29 |