vuex 在非组件中调用 actions 方法 asing1elife | 2018-08-14 | vue , vuex 版权声明:本文首发 http://asing1elife.com ,转发请注明出处,讲文明懂礼貌! 一般情况下调用 actions.js 中的方法都是在组件中,如果想在非组件中调用,则需要如下方式 在组件中 1234567891011121314import {mapActions} from 'vuex' export default { methods: { ...mapActions([ 'setUserInfo' ]) }, init() { let user = {} this.setUserInfo(user) } } 在非组件中 1234567import store from 'store' function init() { let user = {} store.dispatch('setUserInfo', user) }