vueblocks / vue-use-utilities

A collection of vue composition-api utilities.
https://vueblocks.github.io/vue-use-utilities/
MIT License
32 stars 7 forks source link

You must use this function within the "setup()" method #21

Closed nattyluke closed 2 years ago

nattyluke commented 2 years ago

Thank you for your work! I'm currently playing around with composition API and vue2. useStore() works as expected in a vue component. When I'm trying to write a composable (which is basically a ts file exporting a function) I can't use useState(), it's giving me the error message from the title of this Issue. So I have to use useStore in my main Component and give it as 'prop'/ variable to my composable? Then useStore ist not better then getting the store directly from the context.

nattyluke commented 2 years ago

aah Problem solved: you should import/get your composables in the root of your setup function and not in a async function inside setup.

xiaoluoboding commented 2 years ago

@nattyluke Yes. it also mentioned in Vue documents: https://vuejs.org/guide/reusability/composables.html#conventions-and-best-practices