-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Store not working in web components #2304
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
Comments
What's the error in the console? |
omg, sorry for the missing error information. I edited the main post |
It looks like vuex is not registered correctly. Is your
Also can you profide a reproduction repo please? It will easier for us to help you 🙂 |
You are talking about VueRouter; did you just misspoke or do you actually mean the router? Because in my setup vuerouter doesn't play in :) The import Vue from 'vue'
import App from './App.vue'
import store from './store'
Vue.config.productionTip = false
new Vue({
store,
render: h => h(App)
}).$mount('#app') I am facing the issue with a freshly created vue-cli project. |
Oh damn, I always confound vuex and vue-router 😢 I will check on my side |
Question not reagarding the bug: document.querySelector('my-configurator').modalOpen() (or some other way to trigger internal methods from the Wecomponent) |
I made a reproduction repo here: https://github.com/Kocal/vue-cli-web-components-store I confirm that building for web app ( Sorry, I don't know enough about web components, I can't help you more 🤷♂️ |
Just to clear out possible misunderstandings: The actual building process is successful for me; since 3.0.0rc13, where a So building the webcomponent, both WITH and WITHOUT a store, seems to work. The store-less version also works in the browser and correctly displays the app, |
Yea sorry, when I mean "it works fine" and "it fails", I actually mean that app (always with store) is displayed when targeting web app, and is not displayed when targeting web component. I look like |
|
Yep |
A web component is a library, conceptually. So its entry point is not So to use vuex in web component target, you need to initialize the store in import store from './store'
// ...
export default {
store,
name: 'app',
// ...
} |
It works! Both in a webcomponent and a library as target. Thank god you people are faster than an ambulance–no way I would've figured that out without your help. Just to be sure now @sodatea But I'm afraid this is not a good idea. PS: is this behaviour documented somewhere? I'm so overworked I probably wouldn't have found it anyways; but this is definitely worth a notice somewhere. |
It's ok to leave it in both.
|
Nice! +1 |
PRs are welcome 😀 |
I really needed this tip and luckily got it from this awesome community in a github issue. This definitely needs to be in the docs aswell: vuejs#2304 (comment)
what is different about projects created using Vue CLI 3.0 that this extra step is now required? |
From the Vuex docs:
Is this somehow possible to set up with a library build target? In lib mode, Vue is externalized, so we can't rely on |
I really needed this tip and luckily got it from this awesome community in a github issue. This definitely needs to be in the docs aswell: #2304 (comment)
Uh oh!
There was an error while loading. Please reload this page.
Version
3.0.1
Node and OS info
node 10.7.0 / npm 6.3.0
Steps to reproduce
– Go to vue-cli GUI
– create new project (vuex, babel, less-css, no typescript)
– make a simple state in vuex:
foo: "bar"
– make it a getter aswell
– go to App.vue
– import mapGetters from vuex
– use mapGetters in computed to get the
foo
value– use it in the App.vue template:
This is foo: {{ foo }}
– build a web component named:
my-component
– open demo.html in a browser
What is expected?
No error
What is actually happening?
Error in console regarding the store :(
Without the store, webcomponents seem to work fine
The text was updated successfully, but these errors were encountered: