반응형
변환 커밋 콜이 실패하는 이유는 무엇입니까?
버튼을 누르면store commit돌연변이를 불러옵니다.매우 간단한 코드인데 "commit" 속성 "commit" of undefined"를 읽을 수 없습니다.내가 뭘 잘못하고 있지?
주의: 스토어 정보는 다른 파일에 포함되어 있습니다만, 그렇게 하지 않아도 같은 문제가 발생합니다.
컴포넌트/App.vue:
<template>
<div id="app">
<button @click="viewNextWeek">button</button>
</div>
</template>
<script>
export default {
name: 'app',
data() {
return {
msg: "TimeLOG"
}
},
methods: {
viewNextWeek: function() {
this.$store.commit('nextWeek');
}
}
}
</script>
<style></style>
스토어 정보를 포함하는 src/store/index.disc:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
today: new Date(),
},
mutations: {
nextWeek() {
alert('test');
}
}
});
src/main.disc:
import Vue from 'vue';
import store from './store';
import App from './components/App.vue';
new Vue({
el: '#app',
render: h => h(App)
})
다음 정보를 제공해야 합니다.store루트 컴포넌트의 옵션을 사용하여 스토어를 모든 하위 컴포넌트에 "인젝트"하는 경우 geting-vuex-state-into-vue-components를 참조하십시오.main.js:
new Vue({
el: '#app',
store,
render: h => h(App)
})
언급URL : https://stackoverflow.com/questions/52524186/vuex-why-does-my-mutation-commit-call-fail
반응형
'programing' 카테고리의 다른 글
| 스탠포드 튜토리얼과 GCC의 경합 (0) | 2022.07.27 |
|---|---|
| 사이트 로드 시 nuxtServerInit이 여러 번 호출되는 이유 (0) | 2022.07.27 |
| Vue 변환 변경 인스턴스(MyArray에서 어레이로) (0) | 2022.07.27 |
| Vuex는 액션을 디스패치할 때 2개의 요소가 상태 변경됨 (0) | 2022.07.27 |
| javax.net.ssl 해결.SSLHandshakeException: sun.security.validator.검증자예외: PKIX 경로 구축에 실패했습니다. 오류? (0) | 2022.07.27 |