반응형
알 수 없는 작업: Vuex를 사용하여 카운터가 증가하지 않음(VueJS)
다음 코드를 사용하여 Vuex를 사용하여 store.js에서 카운터를 증분하고 있다.왜 그런지 모르겠지만, 증분 버튼을 클릭하면 다음과 같이 적혀 있어.
[vuex] 알 수 없는 작업 유형: INCRING
store.js.
import Vuex from 'vuex'
import Vue from 'vue'
Vue.use(Vuex)
var store = new Vuex.Store({
state: {
counter: 0
},
mutations: {
INCREMENT (state) {
state.counter++;
}
}
})
export default store
IcrementButton.부에를 하다
<template>
<button @click.prevent="activate">+1</button>
</template>
<script>
import store from '../store'
export default {
methods: {
activate () {
store.dispatch('INCREMENT');
}
}
}
</script>
<style>
</style>
당신은 사용해야만 한다.commit
동작이 아닌 돌연변이를 트리거하는 방법:
export default {
methods: {
activate () {
store.commit('INCREMENT');
}
}
}
작용은 돌연변이와 유사하며, 차이점은 다음과 같다.
- 그 상태를 변이하는 대신, 행동은 변이를 저지른다.
- 작업은 임의의 비동기 작업을 포함할 수 있다.
참조URL: https://stackoverflow.com/questions/41255516/unknown-action-counter-not-incrementing-with-vuex-vuejs
반응형
'Programing' 카테고리의 다른 글
v-for를 사용하여 어레이의 일부만 반복하는 방법 (0) | 2022.05.04 |
---|---|
역추적()/backtrace_symbols() 기능 이름을 인쇄하는 방법? (0) | 2022.05.04 |
들여쓰기 #defines (0) | 2022.05.04 |
Vuex 비동기식 계산 이미지가 제대로 작동하지 않는 v-carouzl을 사용하여 Vuetify (0) | 2022.05.04 |
?: 한 식을 비워둘 때 3차 조건부 연산자 동작 (0) | 2022.05.04 |