Skip to content
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

Unable to use Vuex + namespace with Typescript #198

Open
eni9889 opened this issue Mar 24, 2020 · 7 comments
Open

Unable to use Vuex + namespace with Typescript #198

eni9889 opened this issue Mar 24, 2020 · 7 comments

Comments

@eni9889
Copy link

eni9889 commented Mar 24, 2020

Hi,

I am doing the following in typescript

Vue.customElement('coupon-preview', new CouponPreview({ store }).$options);

But I am getting the following error because the store is not present in the new component:

Cannot read property '_modulesNamespaceMap' of undefined"

If I instead do

Vue.customElement('coupon-preview', new CouponPreview({ store }));

The store is there but the component fails to render:

template or render function not defined

Anything I can do to include the store in typescript?

I also tried the suggestion here but no dice #161

@karol-f
Copy link
Owner

karol-f commented Mar 24, 2020

Maybe const component = new CouponPreview({ store })

And

Vue.customElement('coupon-preview', component.$options);?

@AlexanderErmoshkin
Copy link

Hi, I'm facing the same issue. Unfortunately such code doesn't fix it:

const component = new App({ store })
Vue.customElement('custom-element', component.$options);

Are there any workarounds?

@eni9889
Copy link
Author

eni9889 commented Mar 24, 2020

@karol-f that does not work either. The only way I got this to work was by manually setting this.$store = store in beforeCreate of the component which is less than ideal

@karol-f
Copy link
Owner

karol-f commented Mar 25, 2020

Unfortunately I don't have much experience with Typescript (yet). PR's are welcome.

We can ask if @isaaclyman can have a look but I assume he is now busy man (like we all due to virus).
Did You try his demo repo - https://github.com/isaaclyman/vue-custom-element-ts-example?

@isaaclyman
Copy link

I don't see any TypeScript-specific annotations or errors. If it were a TS issue, casting to any would solve it.

@karol-f
Copy link
Owner

karol-f commented Mar 31, 2020

There was minor fix by @qpitlove (#200) - I don't know if it's related

@outcomes-keyan-hardman
Copy link

outcomes-keyan-hardman commented Dec 8, 2020

If anyone stumbles upon this thread I found an extremely simple solution to this issue. This works for issues with VueX store as well as Vue Router.

When defining your parent component you can do the following -

@Component({ store, router })
export default class App extends Vue {}

In your main.ts -

//vue-custom-element & IE11 polyfill
import VueCustomElement from 'vue-custom-element';
import 'document-register-element/build/document-register-element';
Vue.use(VueCustomElement);
Vue.customElement('your-new-tag', (new App().$options));

You will then be able to access your vuex-class namespaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants