Akryum / vue-supply

Create resources that can automatically be activated and deactivated when used (like subscriptions)
159 stars 16 forks source link

[Solved] Getting TypeError: Cannot read property issue #12

Closed tdwells90 closed 6 years ago

tdwells90 commented 6 years ago

Hi Akryum,

I really appreciate the work put into these packages. They're all fantastic!

I'm using Vue-supply with Meteor and although what I want works, I'm getting console errors:

    mixins: [
        use( 'Settings' ),
    ],
    computed: {
        settings() {
            return this.$supply.Settings.settings;
        }
    },

    metaInfo() {
        if( this.settings.appName ) {

            return {
                title: 'Settings | ' + this.settings.appName,
                meta: [
                    { description: 'Settings | ' + this.settings.appName },
                    { property: 'og:description', content: 'Settings | ' + this.settings.appName }
                ]
            }
        }
    },

Basically, what I'm doing above is getting the settings from a meteor collection (everything is set up like your docs!) and although appName is being rendered fine (both in the <head> and in the page itself) I'm getting the following console errors:

TypeError: Cannot read property 'Settings' of undefined
    at VueComponent.settings (Settings.vue:84)
    at Watcher.get (modules.js?hash=8a2a2d2531dccd352022a8c4f2586359dda07b51:28700)
    at Watcher.evaluate (modules.js?hash=8a2a2d2531dccd352022a8c4f2586359dda07b51:28807)
    at VueComponent.computedGetter [as settings] (modules.js?hash=8a2a2d2531dccd352022a8c4f2586359dda07b51:29058)
    at VueComponent.metaInfo (Settings.vue:89)

and

[Vue warn]: Error in created hook: "TypeError: Cannot read property 'Settings' of undefined"

found in

---> <Settings>

Everything seems fine as per your docs and examples (I copied a lot of what you did in your meteor demo project for this) but I can't seem to get rid of these console errors despite everything else working fine!

Thanks in advance for any help.

Cheers.

Tom.

tdwells90 commented 6 years ago

This is now resolved. I think I was making the wrong approach.

I wanted to keep my app fairly simple and avoid using Vuex, but I think for the settings (which are global for the whole site) then it was the only solution. As such, using supply with Vuex has got rid of my console errors!

In short, there's always a use-case for an application state management solution and in this case it was required :)