首页 > 解决方案 > VueJS 3 全局注册导入

问题描述

我可能有一个简单的问题,但我并没有真正知道如何去做。

我想使用Sweetalert2并在我拥有的每个 VueJS 组件中全局使用它。所以在我的 app.js 我有这个:

import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import { Head, Link } from '@inertiajs/inertia-vue3'
import { InertiaProgress } from '@inertiajs/progress'
import { Swal } from 'sweetalert2'


createInertiaApp({
  resolve: name => require(`./Pages/${name}`),
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .use(Swal)
      .component('Link', Link)
      .component('Head', Head)
      .mount(el)
  },
})

由于某种原因,这仍然会出现此错误:( 图片)

标签: javascriptvue.jsvuejs3inertiajs

解决方案


您是否尝试过使用默认导入

import Swal from 'sweetalert2'

推荐阅读