在我的nuxt3应用程序中,我正在尝试安装vue3-spinner
包。下面是我的实现:
// file: @/plugins/vue3-spinner.js
import vue3Spinner from 'vue3-spinner'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(vue3Spinner)
})
// file: @/components/MyComponent.vue
<script setup>
import { DotLoader } from "vue3-spinner"
console.log(DotLoader)
</script>
**问题:**我得到这个500错误:
require is not defined in ES module scope, you can use import instead This file is being treated as an ES module because it has a '.js' file extension and '/Users/me/projects/my-nuxt-app/node_modules/vue3-spinner/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
我做错了什么?
1条答案
按热度按时间yftpprvb1#
您需要确保此插件仅在客户端运行。否则,你会得到一个错误。
~/plugins/spinner.client.js
我在这里创建了一个示例demo。https://stackblitz.com/edit/nuxt-starter-qfccjy?file=plugins/spinner.client.js
希望对你有帮助。