laravel - How Can I Install sweetalert2 via Laravel-Mix?
问题描述
STEP1: In console/terminal.
npm install --save sweetalert2
STEP2: In app.scss add this line...
@import '~sweetalert2/src/sweetalert2.scss';
STEP3: In app.js add this line...
const swal = require('sweetalert2');
STEP4: In webpack.min.js...
mix.setPublicPath('public');
mix.js('resources/js/app.js', 'js');
mix.sass('resources/sass/app.scss', 'css');
STEP5: npm run dev
STEP6: Add app.js and app.css to HTML document
I got this error:
Uncaught ReferenceError: swal is not defined
What's the missing step?
解决方案
If you want to make it available anywhere you would have to tie it to the window:
const swal = window.swal = require('sweetalert2');
But a better way would be to include it in any file you use it in, the same way you did in app.js
推荐阅读
- javascript - React:使用自定义钩子处理动态引用
- reactjs - 单击删除按钮时,使用 Reactjs Table 行不会被删除
- python - python中的条件分组
- python - Discord.py 排行榜命令不起作用
- arrays - Pyspark 展平数组并分解结构以获得所需的输出
- javascript - 带有反应钩子的单元测试失败
- java - 如何跳过或删除 EntityExistsException 的原因?
- sql - SQL Server 阻塞链
- python - Debian10 python3问题
- java - Android Studio - setQuery 在第一次搜索时不起作用