首页 > 解决方案 > 在 vuex 模块操作中访问 vue 根实例

问题描述

根据 github,访问 vue root 实例在操作中非常容易。

https://github.com/vuejs/vuex/issues/1399

我已经对其进行了测试,它可以正常工作。这是我的商店设置:

export default new Vuex.Store({
    actions: {
        testPieter (context) {
            console.log('this in testpieter', this)
            console.log('vm in testpieter', this._vm)
        }
    },
    modules: {
      userStore,
      notifications,
      safetyDrone
  },
  strict: debug
})

问题是,在模块中的操作中,当我从操作中 console.log 存储时,我似乎无法访问 vue 实例:

在此处输入图像描述

当我从操作中获得 console.log(this) 时,我只得到模块文件中定义的导出..

是否有一种内置/优雅的方式来访问 vue 根实例?

标签: javascriptvue.jsvuex

解决方案


推荐阅读