仅客户端NUXT 3 VUE插件
我是Nuxt和Vue的新手,所以请轻松对我。我正在尝试使用 vue3-vue3-video-player ,这似乎不基于以下错误支持SSR,当我在视频组件中导入它时会遇到的:
reference eRseRor:Navigator未定义
即使使用<<&lt; clientonly&gt; 。因此,根据我在 nuxt 3文档我想我想创建位于>插件/vue3-video-player.client.js
的仅限客户端插件,具有以下内容
import Vue3VideoPlayer from '@cloudgeek/vue3-video-player'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(Vue3VideoPlayer)
})
: player&gt; ,我会收到以下错误:
[vue warn]:无法解析组件:vue3-video-player
,
所以我想我的问题是如何创建一个仅客户端VUE使用NUXT 3插件的组件?还是完全不同的方法可以更好?
I am new to Nuxt and Vue, so go easy on me. I am trying to create a video player component in my Nuxt 3 app using vue3-video-player, which doesn't seem to support SSR based on the following error I get when I import it in my video component:
ReferenceError: navigator is not defined
This error persists even if the component is wrapped with <ClientOnly>
. So, based on what I saw in the Nuxt 3 Documentation I thought I would create a client-only plugin located at plugins/vue3-video-player.client.js
with the following contents:
import Vue3VideoPlayer from '@cloudgeek/vue3-video-player'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(Vue3VideoPlayer)
})
But when I try to use it in my component as <vue3-video-player>
, I get the following error:
[Vue warn]: Failed to resolve component: vue3-video-player
So I guess my question is how do I create a client-only Vue component using Nuxt 3 plugins? Or is there an entirely different approach that would work better?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NUXT 3
的解决方案:NUXT将自动读取插件目录中的文件并加载它们。您可以使用
.server
或.client
文件名中的后缀以仅在服务器或客户端端加载插件。例如:
插件/apexcharts.client.ts
一切都很简单!这就是为什么我们喜欢
nuxt
❤️nuxt 2
的解决方案(显示差异):nuxt.config.ts
这仅适用于<代码> NUXT 2 因为NUXT 3
插件/
目录均为自动注册单独使用nuxt.config
。Solution for
nuxt 3
:Nuxt will automatically read the files in your plugins directory and load them. You can use
.server
or.client
suffix in the file name to load a plugin only on the server or client side.For example:
plugins/apexcharts.client.ts
Everything is so simple! And that is why we love
nuxt
❤️Solution for
nuxt 2
(to show the difference):nuxt.config.ts
This is only for
nuxt 2
because All plugins in your nuxt 3plugins/
directory are auto-registered, so you should not add them to yournuxt.config
separately.标记给定的正确答案在这里,
如果您要安装和使用第三方NPM软件包,并且插入“窗口未定义”键入错误,您可以将软件包作为插件加载为如下(例如 wad )
To tag along with the given correct answer here,
If you're trying to install and use a third party NPM package, and running into "window is not defined" type errors, you can load the package as a plugin as follows (eg WAD)
您可以尝试提供辅助功能。如 docs 。
you could try to provide a helper function. As mentioned in the docs.