sourcetip

Vuex 모듈, 돌연변이 및 액션에 ES6 클래스를 사용해도 괜찮습니까?

fileupload 2023. 7. 2. 20:54
반응형

Vuex 모듈, 돌연변이 및 액션에 ES6 클래스를 사용해도 괜찮습니까?

다음과 같은 방법으로 재사용 가능한 Vuex 모듈을 만들 예정입니다.

// parent class to keep all the common CRUD actions
class ListModule {
    state: getInitialState(),
    actions: new ListActions(),
    mutations: new ListMutations()
}

...
class FooMutations extends ListMutations {
    // some additional mutations
}

// class with parent's actions and data structure, but modified mutations
class FooModule extends ListModule {
    mutations: new FooMutations()
}

이것이 제가 CRUD 작업의 중복을 피하고 필요한 경우 특정 모듈에 대해 확장하고 싶은 방법입니다.

모든 모듈은 네임스페이스와 함께 사용됩니다.

잠재적인 문제가 있습니까?

가능할 수도 있지만 물건이 필요할 때 수업을 이용하는 것은 불필요하게 복잡해 보입니다.

const listMutations = {
  // mutations here
}

// 'extend' listMutations
const fooMutations = {
  ...listMutations,
  // some additional mutations
}

const listModule = {
  state: getInitialState(),
  actions: listActions,
  mutations: listMutations
}

// 'extend' listModule
const fooModule = {
  ...listModule,
  mutations: fooMutations
}

언급URL : https://stackoverflow.com/questions/57570321/is-it-ok-to-use-es6-classes-for-vuex-modules-mutations-and-actions

반응형