如何在NUXT 3项目中使用vue3组件(vue.draggable.next)作为插件
在我最近开始的项目中,我想使用 vue.draggable.next.next 。因此,我在NUXT插件目录中创建了一个“ .js”文件,并添加代码如下。
import VueDraggableNext from "vue-draggable-next";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueDraggableNext);
});
然后,我在下面的一个组件中使用它,
<template>
<div class="h-full w-full border-2 border-dashed rounded-lg p-5 flex">
<div class="flex w-1/6 h-full">
<ComponentPalette />
</div>
<VueDraggableNext
v-model="form.children"
group="people"
@start="isDragOver = true"
@end="isDragOver = false"
item-key="id"
class="flex flex-col w-5/6 h-full border-blue-700 border-2 border-dashed rounded-lg p-5 space-y-5"
>
<template #item="{element}">
<FormBuilder
:component="element"
@update="update"
/>
</template>
</VueDraggableNext>
</div>
</template>
<script setup>
import FormBuilder from "~~/components/dynamic-components/FormBuilder.vue";
import ComponentPalette from "~~/components/form-builder/ComponentPalette.vue";
import { v4 as uuidv4 } from "uuid";
const form = reactive({
formId: "abcd-1234",
formName: "User Registration",
children: [],
});
const isDragOver = ref(false);
</script>
<style scoped></style>
一旦运行该项目,我将遇到以下错误:
[Vue warn]: A plugin must either be a function or an obj
ect with an "install" function.
[Vue warn]: Failed to resolve component: VueDraggableNex
t
If this is a native custom element, make sure to exclude
it from component resolution via compilerOptions.isCust
omElement.
如何在NUXT3项目中正确使用此VUE插件?
In my recently started project, I wanted to use a vue.draggable.next. So I created a ".js" file inside the nuxt plugin directory and I add code as below.
import VueDraggableNext from "vue-draggable-next";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueDraggableNext);
});
Then I used it in one of my components as below,
<template>
<div class="h-full w-full border-2 border-dashed rounded-lg p-5 flex">
<div class="flex w-1/6 h-full">
<ComponentPalette />
</div>
<VueDraggableNext
v-model="form.children"
group="people"
@start="isDragOver = true"
@end="isDragOver = false"
item-key="id"
class="flex flex-col w-5/6 h-full border-blue-700 border-2 border-dashed rounded-lg p-5 space-y-5"
>
<template #item="{element}">
<FormBuilder
:component="element"
@update="update"
/>
</template>
</VueDraggableNext>
</div>
</template>
<script setup>
import FormBuilder from "~~/components/dynamic-components/FormBuilder.vue";
import ComponentPalette from "~~/components/form-builder/ComponentPalette.vue";
import { v4 as uuidv4 } from "uuid";
const form = reactive({
formId: "abcd-1234",
formName: "User Registration",
children: [],
});
const isDragOver = ref(false);
</script>
<style scoped></style>
once I run the project I will get following errors:
[Vue warn]: A plugin must either be a function or an obj
ect with an "install" function.
[Vue warn]: Failed to resolve component: VueDraggableNex
t
If this is a native custom element, make sure to exclude
it from component resolution via compilerOptions.isCust
omElement.
How can I use this vue plugin properly in a nuxt3 project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VUE插件和NUXT插件之间有一些差异。您要尝试的是创建一个使用VUE组件的NUXT插件。因此,为了做到这一点,您需要将代码更新为:
区别在于您在VUEAPP中注册组件的方式。另外,随着此更改,您需要将HTML模板中的组件名称更新为
&lt; lt; gt;
,如果您想了解更多信息,请在此处遵循一些有用的链接:
have some differences between a Vue Plugin and a Nuxt Plugin. What you are trying to do is create a Nuxt Plugin to use a Vue Component. So in order to do this, you need to update your code to:
The difference is the way you are registering the component in vueApp. Also with this change, you will need to update the component name inside the html template to
<draggable>
Here follow some useful links if you want to know more: