Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing the $store #22

Closed
ukjeep4x4 opened this issue Jun 6, 2018 · 6 comments
Closed

accessing the $store #22

ukjeep4x4 opened this issue Jun 6, 2018 · 6 comments

Comments

@ukjeep4x4
Copy link

i see you can pass in a variable to the options called store where you can access the store to get values(using in fetch data), but i'm getting some weird errors.

Uncaught (in promise) TypeError: Cannot read property 'state' of undefined
at a (liquor-tree.esm.js?6487:6)
at VueComponent.connectStore (liquor-tree.esm.js?6487:6)
at eval (liquor-tree.esm.js?6487:6)

how i'm calling it/configuration:

<tree v-if="websiteId != 0" :options="treeOptions" @node:selected="onNodeSelected" />

treeOptions: {
store: this.$store,
fetchData (node) {
return HTTP.get(/api/websitenavigation?nodeid=${node.id}&websiteId=${this.store.getters.websiteId}).then(function (response) { return response.data })
}
}

if i take out the store: this.$store and hard code the id (${this.store.getters.websiteId}, i get exactly as i would expect it to work. any ideas or help?

thanks,
matt

@ukjeep4x4
Copy link
Author

maybe a better question is how can i access a variable on the page or in the store from the fetchdata function?

@amsik
Copy link
Owner

amsik commented Jun 7, 2018

Probably your case isn't connected to the library. Could you try this code:

treeOptions: {
  store: this.$store,
  fetchData: (node) => {
    return HTTP.get(`/api/websitenavigation?nodeid=${node.id}&websiteId=${this.store.getters.websiteId}`)
    .then(function (response) { return response.data })
    .catch(function (err) { console.log(err); })
  }
}

@ukjeep4x4
Copy link
Author

Uncaught (in promise) TypeError: Cannot read property 'state' of undefined
at a (webpack-internal:///./node_modules/liquor-tree/dist/liquor-tree.esm.js:6)
at VueComponent.connectStore (webpack-internal:///./node_modules/liquor-tree/dist/liquor-tree.esm.js:6)
at eval (webpack-internal:///./node_modules/liquor-tree/dist/liquor-tree.esm.js:6)

@ukjeep4x4
Copy link
Author

image

@ukjeep4x4
Copy link
Author

image

@amsik
Copy link
Owner

amsik commented Jun 7, 2018

Oh, you have wrong options object. Check this page:

https://amsik.github.io/liquor-tree/#Integration-with-Vuex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants