我正在尝试在python manage.py runserver
中使用bugsnagClient及其notify方法,在plugins/axios.js
中有此代码
plugins/bugsnag.js
我想将方法附加到import Vue from "vue"
import bugsnag from "@bugsnag/js"
import bugsnagVue from "@bugsnag/plugin-vue"
// const bugsnagClient = bugsnag(`${process.env.BUGSNAG_API_KEY}`)
var bugsnagClient = bugsnag({
apiKey: "",
notifyReleaseStages: ["production"]
})
bugsnagClient.use(bugsnagVue, Vue)
或app
上
context
我想在export default ({ app }, inject) => {
function bugsnagNotify(error) {
return bugsnagClient.notify(new Error(error))
}
// Set the function directly on the context.app object
app.bugsnagNotify = bugsnagNotify
}
plugins/axios.js
在此文件中,当我只为export default function({ store, app }) {
if (store.getters.token) {
console.log(app.bugsnagNotify("ss"))
app.$axios.setToken(store.getters.token, "Bearer")
} else {
//app.$bugsnag.notify(new Error("Bearer tooken is missing in Axios request."))
}
}
做console.log
我可以看到app
但是当我打电话给bugsnagNotify: ƒ bugsnagNotify(error)
时,只会收到诸如app.bugsnagNotify("error")
这样的错误消息
我也在VM73165:37 TypeError: app.bugsnagNotify is not a function
plugins/bugsnag.js
我只得到一个错误
export default (ctx, inject) => {
inject('bugsnag', bugsnagClient)
}
答案 0 :(得分:0)
如果要在一个插件内部注入上下文,并想在另一个插件内部使用该功能,则需要确保要注入的插件首先位于nuxt.config.js
...
plugins: [
'~/plugins/bugsnag.js',
'~/plugins/axios.js'
],
...