本文实例为大家分享了vue.js计数器的制作方法,供大家参考,具体内容如下
src/components
Hello.vue
Now count is {{counterValue}}
Increate.vue
<style lang="css">
src/vuex
store.js
Vue.use(Vuex)
const state = {
count: 0
}
const mutations = {
INCREMENT (state,n) {
state.count = state.count + n
},REDUCE (state) {
state.count--
}
}
export default new Vuex.Store({
state,mutations
})
action.js
502_43@ dispatch('INCREMENT',3)
export const reduceCounter = ({dispatch}) => dispatch('REDUCE')
getters.js
src/App.vue
<div class="jb51code">
<pre class="brush:xhtml;">