Programing

알 수 없는 작업: Vuex를 사용하여 카운터가 증가하지 않음(VueJS)

c10106 2022. 5. 4. 21:13
반응형

알 수 없는 작업: 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

반응형