vexip-ui / nuxt

Nuxt Module for Vexip UI.
MIT License
35 stars 1 forks source link

How to use components with Nuxt Content? #1

Open Extarys opened 1 year ago

Extarys commented 1 year ago

Description

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

Validations

qmhc commented 8 months ago

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>