Error in v-on handler: "TypeError: this.$store.dispatch is not a function"
문제내용
- Vue의 컴포넌트에서 검색버튼을 누르면 Vuex의 actions에 정의한 test함수가 작동되길 바랬지만 오류 발생
해결내용
- 구글링결과 Vuex코드를 작성하는 store.js에서 store를 정의할 때
export default new Vuex.Store({내용});
로 정의하라는 내용을 발견
- 기존에는
export const store = {내용}
로 정의
export const store = { }
를 export default new Vuex.Store({});
로 변경하고 main.js
에서 store
를 import
할 때 사용하던 {}
를 삭제
결과
- 검색창에 적힌 텍스트를 1초 뒤에 콘솔창에 띄우는 test함수가 작동하고 결과가 나오는 것을 확인
