반응형
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>
당신은 그 일을 놓치고 있다.state
add고객 함수 매개 변수(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
반응형
'programing' 카테고리의 다른 글
Java에서 상속을 금지해야 하는 좋은 이유? (0) | 2022.04.25 |
---|---|
Vuejs에서, 모델을 단추에 묶는 것이 가능한가? (0) | 2022.04.25 |
8진수 리터럴:언제? 왜? 한번도? (0) | 2022.04.25 |
계산된 속성을 통해 Vuex 상태 변경에 대한 구성 요소 업데이트 (0) | 2022.04.25 |
하위 디렉터리의 Vuex 액세스 모듈 (0) | 2022.04.25 |