composition-api
composition-api copied to clipboard
fix: useAsync runing server and client at the same time
🐛 The bug What isn't working? Describe what the bug is.
🛠️ To reproduce
Steps to reproduce the behavior:

I use vue2.7 in setup use "useAsync" it being executed in server and client
🌈 Expected behaviour useAsync only executed in server or client
ℹ️ Additional context https://github.com/szptWangrs/nuxt-template.git
useAsync is meant to return a value. If no value is returned it will run it again.
@danielroe so useFetch cant be used to dispatch vuex calls, and useAsync cant be used to dispatch vuex calls ( as they store into state and not used directly retunred values usually). What left then?
@aldarund You can use it to do that: https://stackblitz.com/edit/github-s9qt7x?file=pages%2Findex.vue. But if you don't want it to be run more than once you will need to ensure a value - any value - is returned.
@danielroe ye i though about it, not so clean solution but anyway. Btw if in your example return empty string instead of dict - it will break and will be called both client and server https://stackblitz.com/edit/github-s9qt7x-pawc6h?file=pages%2Findex.vue