仅NUXT本地导入客户端
我正在尝试使用 vueplyr 在nuxt 2中插件/plugins/vue-plyr.js
,
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import 'vue-plyr/dist/vue-plyr.css'
Vue.use(VuePlyr)
但它只是在一个页面中使用,因此我想从主捆绑包中删除它,并在使用时在本地导入它。我已经在页面中尝试了此(模板部分使用插件时正在工作)。
<template>
<client-only>
<vue-plyr>
<div data-plyr-provider="vimeo" :data-plyr-embed-id="id" />
</vue-plyr>
</client-only>
</template>
<script>
import 'vue-plyr/dist/vue-plyr.css'
import Vue from 'vue'
export default {
async mounted () {
const VuePlyr = await import('@skjnldsv/vue-plyr')
Vue.use(VuePlyr)
}
}
</script>
但是不幸的是,我知道
[Vue warn]: Unknown custom element: <vue-plyr> - did you register the component correctly?
该如何实现这一问题吗?与如何在NUXT中进行动态导入?
I'm trying to use VuePlyr in Nuxt 2. Right now I have it working as a plugin /plugins/vue-plyr.js
,
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import 'vue-plyr/dist/vue-plyr.css'
Vue.use(VuePlyr)
but it is just used in one page, so I would like to remove it from the main bundle and just import it locally when used. I've tried this in my page (the template part was working when using the plugin).
<template>
<client-only>
<vue-plyr>
<div data-plyr-provider="vimeo" :data-plyr-embed-id="id" />
</vue-plyr>
</client-only>
</template>
<script>
import 'vue-plyr/dist/vue-plyr.css'
import Vue from 'vue'
export default {
async mounted () {
const VuePlyr = await import('@skjnldsv/vue-plyr')
Vue.use(VuePlyr)
}
}
</script>
but unfortunately, I'm getting this error
[Vue warn]: Unknown custom element: <vue-plyr> - did you register the component correctly?
Any idea how I could achieve this? Related with How to make a dynamic import in Nuxt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那样导入。
您可以如A
You could import it like that
As mentioned in a previous answer.
在您的nuxt配置中,将插件定义为客户端:
然后请确保围绕组件的使用围绕客户端标签:
编辑:如果将其添加为插件,则不需要在挂载的方法中再次导入组件
In your nuxt config define the plugin as client only:
Then also make sure there's a client-only tag around the use of the component:
Edit: importing the component again in the mounted method isn't necessary if you added it as a plugin