Can't access Vuex from a custom view component.
See original GitHub issueI am using vuejs-dialog in a NUXT project.
My modals are with custom rendering (component).
Here is my setup:
// ~/nuxt.config.js
export default {
...
plugins: [
...
{src: "~/plugins/vuejs-dialog", ssr: false},
...
]
...
};
// ~/plugins/vuejs-dialog.js
import Vue from "vue";
import VuejsDialog from "vuejs-dialog";
import CustomModal from "~/components/modal-custom.vue";
Vue.use (VuejsDialog);
Vue.dialog.registerComponent ("my-custom-modal", CustomModal);
And my custom component:
<template>
<div>
{{ customProp }}
</div>
</template>
<script>
export default {
name: "MyCustomModal",
computed: {
customProp: function () {
return this.$store.getters ['some-store/GET_SOMETHING'];
}
}
};
</script>
<style lang="stylus">
</style>
The problem
$store
is not available to the component and I get the following error:
vue.runtime.esm.js:3142 Uncaught TypeError: Cannot read property 'getters' of undefined
at VueComponent.url (modal-social-sharing.vue?./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options:72)
at Watcher.get (vue.runtime.esm.js:3137)
at Watcher.evaluate (vue.runtime.esm.js:3244)
at VueComponent.computedGetter [as url] (vue.runtime.esm.js:3500)
at eval (eval at mounted (modal-social-sharing.vue?./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options:NaN), <anonymous>:1:6)
at VueComponent.mounted (modal-social-sharing.vue?./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options:83)
at callHook (vue.runtime.esm.js:2916)
at Object.insert (vue.runtime.esm.js:4149)
at invokeInsertHook (vue.runtime.esm.js:5944)
at VueComponent.patch [as __patch__] (vue.runtime.esm.js:6163)
Is $store
getting passed to the created dialog?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Vuex child components cannot access this.$store (undefined)
Use Destructuring when importing store into your main.js file. Change your code from import Vue from 'vue' import App from '.
Read more >Vue and Web Components - Vue.js
Vue's scoped slots are a powerful mechanism for component composition, which can't be supported by custom elements due to native slots' eager nature....
Read more >Modules | Vuex
When you set preserveState: true , the module is registered, actions, mutations and getters are added to the store, but the state is...
Read more >State - Vuex
So how do we display state inside the store in our Vue components? ... all these computed properties can get repetitive and verbose....
Read more >Custom Directives - Vue.js
We have introduced two forms of code reuse in Vue: components and composables. ... for reusing logic that involves low-level DOM access on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, this is my custom view on nuxt
In my custom view,
Hi guys, in main.js of the application:
` import VuejsDialog from “vuejs-dialog”;
import store from ‘./store’ Vue.use(VuejsDialog, { store }) ` then you have the store in the options of the plugin
in the Plugin.prototype.mountIfNotMounted function you have to pass this to the Dialogconstructor
let Vm = new DialogConstructor( { store: this.options.store } )