Answer the question
In order to leave comments, you need to log in
Split getter/mutation/action Vue + Typescript?
Example 1
// store/modules/user.ts
import { VuexModule, Module, Mutation, Action } from 'vuex-module-decorators'
@Module({ namespaced: true, name: 'test' })
class User extends VuexModule {
public name: string = ''
@Mutation
public setName(newName: string): void {
this.name = newName
}
@Action
public updateName(newName: string): void {
this.context.commit('setName', newName)
}
}
export default User
Answer the question
In order to leave comments, you need to log in
I am making one module per entity. There is no point in splitting the entity itself into separate files. This is SOLID, which "Example 4" just violates somewhat. But sometimes several entities use a repeating state and behavior, so it’s worth taking it out separately and fumbling between modules. This is DRY. That is, the division is based on functionality, and not on type. Whether 'vuex-module-decorators' is used or not. It's the same with components.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question