Content: Cannot import components inside a markdown file

Created on 14 Jul 2020  路  9Comments  路  Source: nuxt/content

image

<template>
    <div class="prose prose-lg mx-auto">
        <nuxt-content :document="page" />
    </div>
</template>

<script>
    export default {
        async asyncData ({ $content, params }) {
            const page = await $content(params.slug || 'index').fetch()

            return {
                page
            }
        }
    }
</script>
---
title: Getting started
description: ''
---

<example></example>

Steps to reproduce

  1. Create a component inside the components/ directory.
  2. Try to include the component in a markdown file.

What is Expected?

See the component on the web page when you navigate to the URL.

What is actually happening?

Seeing an error in the console (screenshot attached.)

bug

Most helpful comment

It seems there is an issue with local components registration in development due to live edit mode.

For now, to solve the issue you can put your components inside components/global/ using Nuxt 2.13+ and setting components: true in your nuxt.config.js, see Vue components > Global components.

You will also be able to disable the live edit feature once #285 is merged.

All 9 comments

I have a similiar situation, can not load the markdown files
image

Hey @alihassan1133, you need to register the <example> component, you can either put your component inside components/global/ to be imported automatically or import the component in your page.

The documentation should help you. Everything is explained : https://content.nuxtjs.org/writing#global-components

What if I don't want to use a component globally? Suppose I have a single component for a single blog page, how would I do that?

I would have only one markdown file and a vue file, where would I import the vue file?

@phiter You have to import the component in the page you use the nuxt-content component:

<script>
import Example from '~/components/example.vue'

export default {
    components: {
         Example
    }
}
</script>

I have the same problem.

Imported as usual, it works in code, but when I move declaration to .md it fails with the same error.

<my-image src="/img/w1/logo.png"></my-image>

Could you provide reproduction links so we help you out?

Thanks!

It seems there is an issue with local components registration in development due to live edit mode.

For now, to solve the issue you can put your components inside components/global/ using Nuxt 2.13+ and setting components: true in your nuxt.config.js, see Vue components > Global components.

You will also be able to disable the live edit feature once #285 is merged.

is this resolved ? in nuxt theme docs it can be override by adding

{
 components: [
//import default components directory and global directory here
    {
      path: 'your custom component dir path',
      global: true
    }
  ]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mathieunicolas picture mathieunicolas  路  4Comments

Rednas83 picture Rednas83  路  3Comments

LukaszRados picture LukaszRados  路  3Comments

adrianschubek picture adrianschubek  路  4Comments

pxwee5 picture pxwee5  路  4Comments