How to get vuex state from a javascript file (instead of a vue component)

后端 未结 4 1345
孤街浪徒
孤街浪徒 2021-02-02 09:06

I am working with vuex (2.1.1) and get things working within vue single file components. However to avoid too much cruft in my vue single file component I moved some functions t

4条回答
  •  自闭症患者
    2021-02-02 10:01

    For anyone wondering how to access a mutation from a javascript file, you can do the following:

    import store from './store'
    store.commit('mutation_name', mutation_argument);
    

    Or for actions,

    store.dispatch('action_name', action_argument)
    

提交回复
热议问题