Using a bootfile inside a bootfile #9097
-
I have currently two bootfiles. One which initializes notify, so that I can use `this.$notify.msg("Hello Wordl") in my Vue files: import { Notify } from 'quasar'
const notify = Notify;
export default async ({ app }) => {
app.config.globalProperties.$notify = {
msg(title, msg, type) {
notify.create({
message: title + (msg ? '<div class="text-caption">' + msg + '</div>' : ''),
type: type || "error",
html: true
})
}
}
} and one which does the api/axios stuff: import { boot } from 'quasar/wrappers'
import axios from 'axios'
// Create axios instance for api
const api = axios.create({
baseURL: process.env.API_URL,
withCredentials: true,
})
export default boot(({ app }) => {
app.config.globalProperties.$axios = axios
app.config.globalProperties.$api = api
})
export { axios, api } and this setup works. Now I wanna add a "global" interceptor for axios (inside the axios bootfile), to show an error notification on each error. Something like this: api.interceptors.response.use((response) => response, (error) => {
notify.msg("An error occured", error.message);
}); Then interceptor is working (i can I already tried to add Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@bernhardh try: // boot/notify.js
import { Notify } from 'quasar'
const notify = {
msg(title, msg, type) {
Notify.create({
message: title + (msg ? '<div class="text-caption">' + msg + '</div>' : ''),
type: type || "error",
html: true
})
}
}
export default async ({ app }) => {
app.config.globalProperties.$notify = notify
}
export { notify } // <--- notice the export
// boot/axios.js
import { notify } from 'boot/notify'
...
api.interceptors.response.use((response) => response, (error) => {
notify.msg("An error occured", error.message);
});
... |
Beta Was this translation helpful? Give feedback.
@bernhardh try: