spinner가 바로 꺼지는 이유
368
55 asked
강의에서 axios 요청이 너무 빨라서 뜨지 않는다라고 설명해주셨는데, 이부분은이 잘못된거 같습니다.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
// using a resolved promise, the 'then' block will be triggered instantly,
// but its handlers will be triggered asynchronously as demonstrated by the console.logs
const resolvedProm = Promise.resolve(33);
let thenProm = resolvedProm.then(value => {
console.log("this gets called after the end of the main stack. the value received and returned is: " + value);
return value;
});
// instantly logging the value of thenProm
console.log(thenProm);
mdn의 설명을 보면, promise가 resolve 된 이후, then() 메서드 안의 핸들러는 비동기적으로 호출 된다고 설명하고 있습니다.
(복사붙여 넣기를 하니 포맷이 이상해져서 읽기 불편한점 죄송합니다)
그래서 테스트를 해보았습니다.
//views/NewsView.vue
created() {
bus.$emit("start:spinner");
// setTimeout(() => {
// }, 3000);
this.$store.dispatch("FETCH_NEWS")
.then(result => {
bus.$emit("end:spinner");
console.log("result");
console.log(result);
return result;
})
.catch(err => {
console.error(err);
});
}
//store/actions.js
export default {
FETCH_NEWS(context) {
fetchNewsList()
.then(res => {
context.commit('SET_NEWS', res.data);
console.log('actions');
console.log(res);
return res;
})
.catch(err => {
console.error(err);
});
},
}
//api/index.js
function fetchNewsList() {
console.log('api call');
return axios.get(`${config.baseUrl}news/1.json`);
}
Answer 4
2
안녕하세요 pius712님, 해당 내용에 대해 이후 강좌에서 설명하고 정정했습니다. 일단 제가 잘못 설명 드린 부분에 대해서 공식 문서까지 확인해가며 정확하게 파악하려고 하신 모습이 넘 보기 좋네요..! :) 말씀하신 것처럼 actions 함수에서 프로미스 리턴하면 됩니다. 아래 강좌를 참고해보세요 :)
깃 권한 요청 드립니다
0
50
1
깃 권한 신청
0
50
1
깃 권한 요청드립니다.
0
111
1
깃허브 권한 요청 드립니다
0
144
1
깃허브 권한 요청 드립니다
0
161
1
깃허브 권한 요청 드립니다
0
167
1
깃허브 권한 요청 드립니다.
0
154
1
안녕하세요 vue 2.7로 수강하고 있는 학생입니다. 실무에서 최하위 자식의 props와 watch의 관계를 여쭈고자 합니다.
0
208
1
ide 타입추론 기능 사용할 수 없을까요??
0
207
1
컴포넌트 링크는 vue peek 익스텐션 설치가 필수인가요??
0
228
1
Vue3로 진행중입니다
1
338
1
Vue router-link 사용시 같은 url이면
1
506
1
vue3 에러 메세지...
1
670
2
id ="app" 중복
0
271
2
use undefined 에러가 나옵니다.
1
318
2
깃허브 권한 요청드립니다.
1
358
2
권한요청드립니다.
1
299
2
Vue3에서 구글 애드센스 탑재하기
1
437
2
코드가 정상 작동 되는건지 ...
1
303
1
강의에서 api를 따로 빼셨는데 얻는 이점이 뭐죠?
1
243
1
vuex 적용시 질문
1
288
2
라우터 버전이 안맞는데 어떤걸 써야하나요
1
385
2
UserView에 id 속성만 undefined로 넘어오는데 이유를 모르겠습니다..
1
455
2
권한요청 드립니다!
1
275
2

