我正在try 使用Vue.Vuexstore 模块中的js插件.

component中,我可以这样称呼它:this.$plugin().然而,在module中,没有设置this.我以为Vue.$plugin()可以工作,因为我用Vue.use(plugin)Vue作为全局变量来初始化插件,但事实并非如此.

如何从模块中引用插件?

推荐答案

在这里提供的例子中,这个问题的答案是Bert:https://codesandbox.io/s/jp4xmzl0xy

    import Vue from 'vue'
    import App from './App'
    import Notifications from 'vue-notification'
    import Vuex from "vuex"
    Vue.use(Notifications)
    Vue.use(Vuex)
    
    let notifier = new Vue()
    
    
    const store = new Vuex.Store({
      state:{},
      actions:{
        notify(context, payload){
          notifier.$notify(payload)
        }
      }
    })
    
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      store,
      template: '<App/>',
      components: { App }
    })

Vue.js相关问答推荐

通过另一个文件调用模块化窗口组件

从组件中检索 Shopware CMS 编辑器中的自定义实体数据

我如何使用 vuejs 在我的 url 中编码一个令牌

手动触发对观察到的对象/数组的更新

使用 Vue.js 清除数组内容和react性问题

我可以在打印 HTML 页面时使用作用域 CSS 吗? (使用 Laravel 和 Vue.js)

Webpack 编译错误:TypeError: __WEBPACK_IMPORTED_MODULE_1__ … is not a function

如何使用 vue.js 和 vue 路由实现当前路由的子菜单的子菜单

Vuetify 复选框:如何停止点击事件?

Vue:在表格中显示嵌套数据

为什么 Vue 路由/Webpack 开发服务器现在在页面刷新时显示无法获取/路径?

在组件的样式部分使用 Vue 变量

如何为 Vue 项目设置 lint-staged?

从 Url 中删除查询字符串参数

Vue更改宽度和内容

v-if inside v-for - 在两列中显示项目列表

这是 v-on:change 的正确用法吗?

您正在运行 Vue 的 esm-bundler 构建

使用 Vee-validate 禁用按钮,直到正确填写表单

超过最大调用堆栈大小 Vuetify