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

Fetching data in a setup script from an url that has ${variable} in the url is not possible. #14722

Closed
SebbeJohansson opened this issue Aug 28, 2022 · 10 comments

Comments

@SebbeJohansson
Copy link

Environment

Nuxt CLI v3.0.0-rc.8 15:57:24
RootDir: /home/projects/nuxt-starter-si1vu3 15:57:27
Nuxt project info: 15:57:27


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-si1vu3?file=pages%2Fblog%2F[slug].vue,pages%2F[...slug].vueexampl%2Ce

Test url:
https://nuxt-starter-si1vu3--3000.local.webcontainer.io/blog/storyblok-datetime-field-with-today-as-default

Describe the bug

I expect it to be possible to use:

const {
  data: blok,
  pending,
  refresh,
} = await useAsyncData(() =>
  $fetch(
    `https://api.storyblok.com/v2/cdn/stories/blog/${route.params.slug}?token=ee04k73GERZuvgzbdMDHqQtt&version=${version}`
  )
);

to pull data in a setup script, but I'm getting computed is not defined when I do that.

If I instead do:

const {
  data: blok,
  pending,
  refresh,
} = await useAsyncData(() =>
  $fetch(
    'https://api.storyblok.com/v2/cdn/stories/blog/' +
      route.params.slug +
      '?token=ee04k73GERZuvgzbdMDHqQtt&version=' +
      version
  )
);

it works fine.

I cant use the working version because of eslint auto formatting it.

Additional context

Even if i make a variable that has the whole URL it still errors if I use ${variable}.

Logs

No response

@516310460
Copy link
Contributor

516310460 commented Aug 29, 2022

The problem was not found. Please provide a correct link
See: https://stackblitz.com/edit/nuxt-starter-b1aatu?file=pages%2Findex.vue,pages%2Faaa%2F[id].vue

@SebbeJohansson
Copy link
Author

@516310460 I dont know what you are on about. That stackblitz seems to be different from the one I posted.
Doing the steps in the reproduction with the proper stackblitz results in this:
image

The only difference between yours and mine is the weird folder of aaa and the template by the looks of it.
Doesnt work:

<template>
  <div class="page blog-entry-page">
    {{ portfolioTitle }}
    {{ story }}
  </div>
</template>

Works:

<template>
  <div>
    aaa/[{{ route.params.id }}].vue
    <nuxt-link to="/">index</nuxt-link>
    {{ portfolioTitle }}
    {{ story }}
  </div>
</template>

I don't see a logic in why that should make computed stop working.

@SebbeJohansson
Copy link
Author

Here is another repro based on your stackblitz: https://stackblitz.com/edit/nuxt-starter-pr2brk?file=pages%2Faaa%2F[slug].vue

@danielroe
Copy link
Member

I would guess that this might be similar to unjs/mlly#64.

@SebbeJohansson
Copy link
Author

@danielroe Is it something that needs to be fixed in nuxt or is there something I need to do?

@danielroe
Copy link
Member

@SebbeJohansson I can't reproduce with the linked stackblitz. Is there a specific URL I need to go to or step I need to take?

@SebbeJohansson
Copy link
Author

@danielroe Yes! I specified it as "Test url" in the oriignal comment. Maybe I wasn't clear enough.
https://nuxt-starter-si1vu3--3000.local.webcontainer.io/blog/storyblok-datetime-field-with-today-as-default

@danielroe
Copy link
Member

My bad - perfect 👍

@antfu - might be a possible unimport issue.

@richgcook
Copy link

I have also had this issue...

const mailChimpUrl = `https://${props.mailChimpUsername}.${props.mailChimpServer}.list-manage.com/subscribe/post-json`

This throws an error with whatever is directly below the variable declation

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@danielroe
Copy link
Member

This is no longer replicable: https://stackblitz.com/edit/nuxt-starter-h35gez.

Let me know if you're still experiencing this and I'd be happy to reopen/look at this again.

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

No branches or pull requests

4 participants