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
Doc: proper way of passing a component to a ionic controller #38
Comments
Thanks @zwacky , I don't mind this at all, github works for the time being, I will investigate this as well, but to save you time, try passing {
component: () => import('path/to/component.vue'),
} |
I tried that approach but didn't work with my component that used vuex. It didn't have access to That is when I tried the |
It does feel weird, what about passing the component directly? import NavBarVolumeSliderPopover from 'path/to/NavBarVolumeSliderPopover.vue'
...
this['$ionic'].popoverController
.create({
component: NavBarVolumeSliderPopover,
translucent: true,
event,
})
.then(modal => modal.present()); From what I can tell, the vuex plugin is not being instantiated properly for it, I'll do further investigations as well |
@zwacky if you could share your code, it could help debug a particular way of doing things :) |
Hey @zwacky , first of all, thanks for this bug submission, it's really awesome that you caught this edge-case. I dug around your code and you basically have 3 options here, due to the fact how Vuex adds the TLDR; The issue is that when you pass a component to ionic-vue it creates a new controller from a Vue instance, even though it has all of the settings and plugins like
this['$ionic'].popoverController
.create({
component: NavBarVolumeSliderPopover,
componentProps: { parent: this },
translucent: true,
event,
})
.then(modal => modal.present());
import store from '@/store';
...
this['$ionic'].popoverController
.create({
component: NavBarVolumeSliderPopover,
componentProps: { store },
translucent: true,
event,
})
.then(modal => modal.present());
|
@zwacky on the same note, turns out all of the above are good options and not "hacks": |
Would it be an idea to make Ionic pass the parent by default? I just encountered this problem, and it took me a while to find this issue |
Not as far as I know, the plugin is being initialized way before you reach the call to ionic controllers. I've looked into it and there's no way for it to "know" which component to set as it's parent out of the box. |
Hey all, I've been playing around with the ionic controllers, to be specific with
popoverController
.Since I'm new to vue—and I see that you can do things in more than just one way—I ended up with the following solution below. On my way there I had these problems:
this.$store
wasundefined
in passed componentThe important part for me was
parent: this
, which made access tothis.$store
and all vuex bindings (throgh vuex-classes) possible.Is there a more vueful way for this? In the end I could add a proper way to the docs here.
I hope you don't mind if I start that possibly leads to improvment of the project by creating this issue—otherwise please direct me in the right direction where to discuss these questions
The text was updated successfully, but these errors were encountered: