STEP1:在控制台/终端中。
npm install --save sweetalert2
STEP2:在app.scss中添加此行...
@import '~sweetalert2/src/sweetalert2.scss';
STEP3:在app.js中添加此行...
const swal = require('sweetalert2');
STEP4:在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:将app.js和app.css添加到HTML文档
我收到此错误:
未捕获的ReferenceError:未定义swal
缺少的步骤是什么?
答案 0 :(得分:3)
如果要使其在任何地方都可用,则必须将其绑定到窗口:
G.nodes(data=True)
> NodeDataView({0: {'weight': 5}, 1: {'weight': -1, 'volume': 4}, 2: {}, 3: {'weight': 2}, 4: {}, 5: {}, 6: {}, 7: {}, 8: {}, 9: {}})
但是更好的方法是将其包含在使用它的任何文件中,就像在const swal = window.swal = require('sweetalert2');
答案 1 :(得分:1)
更新/resources/js/bootstrap.js.
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
require('sweetalert2');
require('bootstrap');
} catch (e) {}
答案 2 :(得分:0)
在bootstrap.js中尝试添加:
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
const Swal = window.Swal = require('sweetalert2');
require('bootstrap');
} catch (e) {}
在app.sass中添加
@import "~sweetalert2/src/sweetalert2";