【发布时间】:2021-09-24 16:40:44
【问题描述】:
我有一个像这样的 vuex 商店:
const state = {
status: '',
};
const getters = {
//...
};
const actions = {
// ...
};
const mutations = {
// ...
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
}
现在我想访问app.config.globalProperties.$notify
在 Vue.js2 中,我使用了 Vue.prototype.$notify 之类的东西,但这不再起作用了。
$notify 也是这样提供的:
app.use(routes)
.provide('notify', app.config.globalProperties.$notify)
.mount('#app')
很遗憾,我还没有在文档中找到任何相关信息。
所以我的问题是:如何在这家商店中注入 $notify 或访问 app.config.globalProperties?
【问题讨论】:
-
实例可用
this._vm。 -
this._vm是undefined:-/ -
您是如何访问它的?它应该在 Vuex 的常规函数中定义,而不是箭头。
-
我在尝试 ``` // ... const mutation = { test (state, {committedItem}) { //... console.log(this._vm) //undefined }, }; export default { namespaced: true, state, getters, actions, mutation, } ```