-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mixin functions (i.e. $bvToast, $bvModal) do not work on Vue 3 #7111
Comments
Hi, I face same problem, I cannot get bvModal by composition API. In my investigation, the following will work for me. |
@EagleTsui Thank you! So, for other people who run into this, you have to call import { getCurrentInstance } from 'vue';
import { BvToast } from 'bootstrap-vue';
const instance = (getCurrentInstance() as any);
setTimeout(() =>
{
// The timeout seems to be need, otherwise _bv__toast is undefined.
const bvToast = instance.ctx._bv__toast as BvToast;
}, 100); |
For anyone who comes across this, I should mention, Also, |
You need place code in setup or onMounted then you can remove the setTimeout |
@EagleTsui That makes sense. And just tested, that worked perfectly. |
This is so weird, i was trying eagleTsui's temporary fix, but if i console log the property exists, but when i try to access it says it's undefined. I'm losing my mind!!!! If i dump a Object.keys, the key is not present. But why if i console log that it is present! |
This worked for me #4472 |
I didn't test it with I think that what made it work is the use of import { getCurrentInstance, nextTick } from 'vue';
export default {
data() {
return {
instanceModal: null,
};
},
methods: {
openFirstOrderModal() {
this.instanceModal.show('modal-first-order');
},
},
mounted() {
const instance = getCurrentInstance();
nextTick(() => {
this.instanceModal = instance.ctx._bv__modal;
});
},
} Libraries:
UpdateAfter posting this I've tried a few more times and this solution is completely unstable: I have several modals in the same page, and on different refreshes one modal works and another doesn't. Besides, the one that works seems to have also Update 2A possible solution for modals is to emit an event on the root. Personally I've tried to avoid using it because it reduces predictability, but it may work as a temporary solution. this.$root.$emit('bv::show::modal', 'modal-first-order'); |
had this issue with
|
|
Describe the bug
When running with
@vue/compat
in{ MODE: 2 }
, it appears that any functions added to Vue instance by a mixin are not available. This includes$bvToast
and$bvModal
.Steps to reproduce the bug
@vue/compat
.this.$bvToast
.Expected behavior
When running with Vue 3, these functions should appear. (It's particularly bad for
$bvToast
, as there's no other way to dynamically create toasts.)Versions
Libraries:
Environment:
Additional context
I'm attempting to upgrade my application to Vue 3 (as an exploratory exercise) and I cannot, for the life of me work out how to use functions added by mixins. Without that, I can't convert the parts of my application that use toasts; they're just broken.
The text was updated successfully, but these errors were encountered: