programing

ReferenceError 상태가 vuex 저장소에 정의되지 않음

prostudy 2022. 4. 25. 21:37
반응형

ReferenceError 상태가 vuex 저장소에 정의되지 않음

나의vuex가게는 이렇게 생겼는데 전화할 때.addCustomer알겠다ReferenceError: state is not defined:

import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: { customers: [] },
  mutations: {
    addCustomer: function (customer) {
      state.customers.push(customer); // error is thrown here
    }
  }
});

바로 이겁니다.addCustomer바인딩/제본:

<template>
    <button class="button" @click="addCustomer">Add Customer</button>
</template>

이것은 에 대한 정의다.addCustomer:

<script>
  export default {
    name: "bootstrap",
    methods: {
      addCustomer: function() {
        const customer = {
          name: 'Some Name',
        };

        this.$store.commit('addCustomer', customer);
      }
    }
  }
</script>

당신은 그 일을 놓치고 있다.stateadd고객 함수 매개 변수(addCustomer: function (customer)) :

     import Vue from 'vue';
     import Vuex from 'vuex';

     Vue.use(Vuex);

     export default new Vuex.Store({
       state: { customers: [] },
       mutations: {
         addCustomer: function (state,customer) {
           state.customers.push(customer); // error is thrown here
         }
       }
     });

참조URL: https://stackoverflow.com/questions/52841842/referenceerror-state-is-not-defined-in-vuex-store

반응형