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

How to use components with Nuxt Content? #1

Open
4 tasks done
Extarys opened this issue Jul 3, 2023 · 1 comment
Open
4 tasks done

How to use components with Nuxt Content? #1

Extarys opened this issue Jul 3, 2023 · 1 comment

Comments

@Extarys
Copy link

Extarys commented Jul 3, 2023

Description

I need to use the Anchor in Nuxt Content, any idea how I can make the component available for MDC?

Validations

@qmhc
Copy link
Contributor

qmhc commented Oct 26, 2023

Sorry for replying so late!

I'm poor in Nuxt MDC, but I think you should define Anchor outside the markdown via some config.

<template>
  <div ref="mdc">
    <MDC />
  </div>
  <Anchor>
    <AnchorLink v-for="item in anchors" :key="item.id" :to="`#${item.id}`">
      {{ item.name }}
    </AnchorLink>
  </Anchor>
</template>

<script lang="ts" setup>
const mdc = ref<HTMLElement>()
const anchors = reactive<{ id: string, name: string }[]>([])

onMounted(() => {
  const links = mdc.value?.querySelectorAll('a.anchor')

  if (!links?.length) return

  // build anchors
})
</script>

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

No branches or pull requests

2 participants