Skip to content

[DOC] Example section for ContentQuery API uses illegal syntax #1979

Closed
@Oddward

Description

@Oddward

Environment

Reproduction

  1. Use the given example in/similar syntax to the example in the ContentQuery API page as the template for your component
  2. Use component in a page

It marks syntax error in the editor and shows compilation error on the site.

Describe the bug

A page was refusing to load for ages coz of a component based on the example. Turns out Vue doesn't allow this:

"If you are mixing named slots with the default scoped slot, you need to use an explicit <template> tag for the default slot. Attempting to place the v-slot directive directly on the component will result in a compilation error. This is to avoid any ambiguity about the scope of the props of the default slot."

Docs example:

<template>
  <main>
    <ContentQuery path="/about/authors" :where="{ type: 'csv' }" v-slot="{ data }">
      <ul>
        <li v-for="author of data" :key="author.name">
          {{ author.name }}
        </li>
      </ul>
      <template #not-found>
        <p>No authors found.</p>
      </template>
    </ContentQuery>
  </main>
</template>

Suggestion:

<template>
  <main>
    <ContentQuery path="/about/authors" :where="{ type: 'csv' }">
      <template v-slot="{ data }"> // or #default
        <ul>
          <li v-for="author of data" :key="author.name">
            {{ author.name }}
          </li>
        </ul>
      </template>
      <template #not-found>
        <p>No authors found.</p>
      </template>
    </ContentQuery>
  </main>
</template>

Additional context

I'm new to Vue & Nuxt. Still couldn't get any content from ContentQuery or queryContent, but the syntax error was solved 😅

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions