Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

fix: useFetch's does not implement static target (payload is not saved) Β #127

Closed
@gnuletik

Description

@gnuletik

πŸ› 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 ! πŸŽ‰

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions