cklmercer / vue-stash

Easily share reactive data between your Vue components.
MIT License
403 stars 29 forks source link

componet not picking up store #17

Closed jigsawsoul closed 7 years ago

jigsawsoul commented 7 years ago

I have a store within my main vue instance which is working fine and has data. I am trying to access that data within a component...

mounted() {
   this.list = this.$store.list;
   console.log('jobs' + this.$store.list);
},

But list is not populated, although I can see within vue dev tools that the list within the store on the root is populated.

Am I missing something?

jigsawsoul commented 7 years ago

It seems as through because the data for the store is being loaded by ajax that the component is mounted before the data is returned, therefore returning no data within this.$store.list

Although is this data not reactive, when the data is finally assigned into the store would the component then not see the data?

jigsawsoul commented 7 years ago

I have resolved this issue by watching the store.

watch: {
    '$store.jobs'() {
                this.list = this.$store.jobs
    }
},

Please let me know if this seem the correct approch

cklmercer commented 7 years ago

Sorry about the delayed reply. This seems like a fine solution. vue-stash doesn't have a built in way to handle this, so using a watcher seems fine. You vue-stash store is after all just a plain javascript object on your root component. Glad you figured this out!