How do I break up my vuex file?

后端 未结 6 754
迷失自我
迷失自我 2020-12-24 08:27

I have a vuex file with a growing mass of mutators, but I\'m not sure of the correct way of splitting it out into different files.

Because I have:

cons

6条回答
  •  梦毁少年i
    2020-12-24 08:46

    In addition to @bigsee's fine answer, if using an index.js file to export the module:

    └── src
        ├── assets
        ├── components
        └── store
              └─ mymodule
                  ├── state.js
                  ├── actions.js
                  ├── mutations.js
                  ├── getters.js
                  └── index.js
    
    

    index.js

    import state from './state'
    import * as getters from './getters'
    import * as mutations from './mutations'
    import * as actions from './actions'
    
    export default {
    
      state,
      getters,
      mutations,
      actions
    }
    

    getters.js

    const getData = state => state.data
    
    export {
      getData
    }
    

    Similar with actions, mutations and state files.

提交回复
热议问题