0.2.0 • Published 6 years ago
vuex-decorator v0.2.0
vuex-decorator
How to use
npm i vuex-decorator
or
yarn add vuex-decorator
Example
import { Store, Mutation, Action, Getter } from 'vuex-decorator'
@Store
class A {
count = 0
@Getter
getCount (state) {
return `count is ${state.count}`
}
@Mutation
incrementSync (state) {
++state.count
}
@Action
async increment ({ commit }) {
setTimeout(() => {
commit('incrementSync')
}, 1000);
}
}
const a = new A()
a
will be
{
state: {
count: 0
},
mutations: {
count (state, v) {
state.count = v
},
incrementSync (state) {
++state.count
}
},
actions: {
async increment ({ commit }) {
setTimeout(() => {
commit('incrementSync')
}, 1000);
}
},
getters: {
getCount (state) {
return `count is ${state.count}`
}
}
}