简体   繁体   English

如何从 Vue 3 插件创建 Nuxt 3 插件? (vue3-markdown-it)

[英]How to create a Nuxt 3 Plugin from Vue 3 Plugin? (vue3-markdown-it)

I am new to Nuxt, and am attempting to turn the Vue plugin vue3-markdown-it into a Nuxt 3 plugin, but am receiving the following error:我是 Nuxt 的新手,正在尝试将 Vue 插件vue3-markdown-it转换为 Nuxt 3 插件,但收到以下错误:

[Vue warn]: Failed to resolve component: Markdown If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

What am I doing incorrectly?我做错了什么?

Nuxt 3 Plugin Documentation Nuxt 3 插件文档

// md-plugin.client.ts
import Markdown from 'vue3-markdown-it'

export default defineNuxtPlugin(nuxtApp => {
    nuxtApp.vueApp.use(Markdown)
})
// index.vue
<template>
    <main>
        <ClientOnly>
            <Markdown :source="content" />
        </ClientOnly>
    </main>
</template>

<script lang="ts" setup>
    const { find } = useStrapi4()
    const {
        data: {
            attributes: { content },
        },
    } = await find('homepage')
</script>

I had a similar problem on different plugin.我在不同的插件上遇到了类似的问题。 I solved the problem by using component instead of plugin.我通过使用组件而不是插件解决了这个问题。

  • Create a new file under the components folder (Markdown.vue).在组件文件夹下创建一个新文件 (Markdown.vue)。

  • Add Markdown codes in this file:在此文件中添加 Markdown 代码:

     <template> <Markdown:source="content" /> </template> <script lang="ts" setup> import { defineProps } from "vue"; import Markdown from 'vue3-markdown-it'; defineProps({ content: { type: any } }); </script>

    You can customize this code.您可以自定义此代码。

  • Delete plugin file (md-plugin.client.ts)删除插件文件(md-plugin.client.ts)

Now <Markdown:source="content" /> will see our generated Markdown component.现在<Markdown:source="content" />将看到我们生成的Markdown组件。 It worked me.它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM