Я пытаюсь использовать bugsnagClient и его метод уведомления в 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)
}
Я получаю только ошибку как
app.$bugsnag.notify(new Error("Bearer tooken is missing in Axios request."))