fix: useFetch's does not implement static target (payload is not saved) Β #127
Description
π The bug
When using useFetch
hook and generating a full-static build (target: static) and nuxt export
, the useFetch payload is not saved.
π οΈ To reproduce
pages/test.vue
export default defineComponent({
setup () {
const name = ref('')
useFetch(async () => {
name.value = await axios.get('https://myapi.com/name')
})
}
})
nuxt.config.js
export default {
target: 'static'
}
yarn run nuxt build && yarn run nuxt export && http-server dist && xdg-open localhost:8080
When I load index and navigate to the page test
, I can see the network request in the Network tab of the browser.
π Expected behaviour
The HTTP request should not be executed on client-side.
βΉοΈ Additional context
I know there is useStatic
but it does not allow to set a server target (if you want to make a second build which get data from client-side), does not support enablePreview
, and other features implemented by nuxt static mode.
Also, useStatic
requires code changes (which is specific to this package) instead of the useFetch
implementation which has the same behavior as Nuxt's Options API.
Btw, thanks for this module :) It's awesome to combine the Composition API with Nuxt ! π