我试图在我的角度项目中包括sweetalert2,但是它会给出编译时的错误。错误/src/app/pages/signup/signup.component.ts:29:16-25 -错误:导出‘默认’(导入为'Swal')在'sweetalert2‘中找不到(模块没有导出)
步进
1.安装sweetalert2 2.在组件.ts文件上导入(从‘sweetalert2’导入Swal )3.使用Swal.fire()调用
/src/app/pages/signup/signup.component.ts:29:16-25 -错误:导出‘默认’(导入为'Swal')在'sweetalert2‘中找不到(模块没有导出)
有人找到解决办法了吗?
发布于 2022-01-26 18:28:34
中包含所需的css & js文件。
"styles": [
"../node_modules/sweetalert2/dist/sweetalert2.css"
],
"scripts": [
"../node_modules/sweetalert2/dist/sweetalert2.js",
],然后,在您的组件中,
那样导入它
import swal from "sweetalert2";那样使用它
swal({
type: 'success',
title: 'your message',
showConfirmButton: false,
timer: 1500
});发布于 2022-05-04 15:18:42
我有一个完全相同的错误,问题是我正在导出组件,因为:
const Component = () => { Swal.fire({ //configs... })
export default Component;我删除了最后一行,改为:
export const Component = () => { Swal.fire({ //configs... })一切又开始运转了。
https://stackoverflow.com/questions/70867527
复制相似问题