$bvToast not accessible from axios interceptor
See original GitHub issueDescribe the bug
When accessing $bvToast from inside a axios interceptor it comes up as undefined.
Steps to reproduce the bug
axios.js
import axios from 'axios';
import VueAxios from 'vue-axios';
import Vue from 'vue';
Vue.use(VueAxios, axios);
bootstrap.js
import Vue from 'vue';
import '@/plugins/bootstrap_custom.scss';
import Toast from 'bootstrap-vue/es/components/toast';
Vue.use(Toast);
axiosErrorHandler.js
import axios from 'axios';
import Vue from 'vue';
axios.interceptors.response.use(r => r, (error) => {
console.log(Vue.prototype);
Vue.prototype.$bvToast.toast(`Server call returned error ${error.response.status}`, {
title: 'Error',
variant: 'error',
});
return Promise.reject(error);
});
main.js
...
import '@/plugins/bootstrap';
import '@/plugins/axios';
import '@/plugins/axiosErrorHandler';
...
-> $bvToast shows up at the console.log as undefined -> get $bvToast shows up at the console.log at location bv-toast.js?3163:243 -> Error because Vue.prototype.$bvToast is undefined -> using this.$bvToast from an component works fine
Expected behavior
Vue.prototype.$bvToast is defined and Vue.prototype.$bvToast.toast works. OR Some remark about this behavior in the docs AND / OR A guide how to correctly implement this in the docs
Versions
Libraries:
- BootstrapVue: 2.0.0-rc.19
- Bootstrap: 4.3.1
- Vue: 2.6.10
- Axios: 0.18.0
Environment:
- Device: PC
- OS: Win 10
- Browser: Chrome
- Version: 74.0.3729.131
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
vue.js, axios, interceptors and toast-notifications
In my example I use interceptors to measure the time an api call takes, and to show a toast "fetching data" automatically, so...
Read more >Axios request interceptor is not working in my vue app
I'm trying to make axios working with a request interceptor. However before a request is made the interceptor is not triggered. What could...
Read more >[Solved]-Bootstrap-vue dynamic toast isn't working-Vue.js
In the module, the this keyword does not refer to the Vue component. The simplest workaround might be to make a second argument...
Read more >How to run Bootstrapvue Toasts inside vuex Module - Laracasts
when I print (this.$bvToast) to console, it gives undefined.. Copy Code createJob ({commit}, payload) { axios.post( ...
Read more >ルミックス 20mm F1.7を導入 - T2O diary
ReferenceError : Cannot access 'MockMyComponent' before initialization. ... When accessing $bvToast from inside a axios interceptor it comes up as undefined.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone who faced the issue, here’s working code:
To get it working (although it won’t have access to the global app $root instance for using
show()
method):