Gij*_*ese 4 vue.js vuex vuejs2
我正在使用以下代码使用Vuex增加store.js中的计数器.不知道为什么,当我点击增量按钮时,它说:
[vuex]未知动作类型:INCREMENT
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
Run Code Online (Sandbox Code Playgroud)
IcrementButton.vue
<template>
<button @click.prevent="activate">+1</button>
</template>
<script>
import store from '../store'
export default {
methods: {
activate () {
store.dispatch('INCREMENT');
}
}
}
</script>
<style>
</style>
Run Code Online (Sandbox Code Playgroud)
export default {
methods: {
activate () {
store.commit('INCREMENT');
}
}
}
Run Code Online (Sandbox Code Playgroud)
行为类似于突变,区别在于:
| 归档时间: |
|
| 查看次数: |
5101 次 |
| 最近记录: |