programing

변환 커밋 콜이 실패하는 이유는 무엇입니까?

prostudy 2022. 7. 27. 21:35
반응형

변환 커밋 콜이 실패하는 이유는 무엇입니까?

버튼을 누르면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

반응형