question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store not working in web components

See original GitHub issue

Version

3.0.1

image

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

26reactions
sodateacommented, Aug 21, 2018

A web component is a library, conceptually.

So its entry point is not main.js, but an entry-wc.js file generated here: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/resolveWcEntry.js

So to use vuex in web component target, you need to initialize the store in App.vue:

import store from './store'

// ...

export default {
  store,
  name: 'app',
  // ...
}
5reactions
chipit24commented, Dec 5, 2018

From the Vuex docs:

When using a module system, it requires importing the store in every component that uses store state, and also requires mocking when testing the component.

Vuex provides a mechanism to “inject” the store into all child components from the root component with the store option (enabled by Vue.use(Vuex)):

Is this somehow possible to set up with a library build target? In lib mode, Vue is externalized, so we can’t rely on new Vue({ store, ... }).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web component not appearing in html file - Stack Overflow
I call this code using my-navbar in the body and script src="components/navbar. js" in the head because my . js file is in...
Read more >
What happened to web components? - LogRocket Blog
HTML imports were abandoned by browser vendors, so even though they're still working with a polyfill, it's not recommended to use them in...
Read more >
Web Components - MDN Web Docs - Mozilla
A guide showing how to use the features of custom elements to create simple web components, as well as looking into lifecycle callbacks...
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >
Vue and Web Components
Using these frameworks entails buying into their technical decisions on how to solve these problems - which, despite what may be advertised, doesn't ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found