Skip to content

Can't access Vuex from a custom view component. #43

@nicroto

Description

@nicroto

I 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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions