我正在try 使用Vue.Vuexstore 模块中的js插件.
在component中,我可以这样称呼它:this.$plugin()
.然而,在module中,没有设置this
.我以为Vue.$plugin()
可以工作,因为我用Vue.use(plugin)
和Vue作为全局变量来初始化插件,但事实并非如此.
如何从模块中引用插件?
我正在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 }
})