英文:
How to install sweetalert2 to laravel 10 vite
问题
I can't have problem w sweetalert2.
I have error in console:
Uncaught ReferenceError: Swal is not defined
at HTMLButtonElement.(list:121:13)
at HTMLButtonElement.dispatch (jquery-3.7.0.js:5135:27)
at elemData.handle (jquery-3.7.0.js:4939:28)
It concerns this part of code (index.blade.php):
<script type="text/javascript">
$(function() {
$('.delete').click(function() {
Swal.fire("hello");
});
});
</script>
In others files I have:
app.blade.php:
<script type="text/javascript">
@yield('javascript')
</script>
bootstrap.js
import 'bootstrap';
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
window.Swal = require('sweetalert2');
require('bootstrap');
} catch (e) {}
package.json
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"watch": "vite build --watch",
"prod": "vite production"
},
"devDependencies": {
"@popperjs/core": "^2.11.6",
"axios": "^1.1.2",
"bootstrap": "^5.2.3",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.56.1",
"vite": "^4.0.0"
},
"dependencies": {
"jquery": "^3.7.0",
"popper.js": "^1.16.1",
"sweetalert2": "^11.7.16"
}
}
app.scss
@import 'sweetalert2/src/sweetalert2.scss';
I install sweetalert2 using command:
npm install sweetalert2
And this add new folder sweetalert in node_modules
When I use npm audit I have:
npm audit report
sweetalert2 >=11.6.14
sweetalert2 v11.6.14 and above contains potentially undesirable behavior - https://github.com/advisories/GHSA-mrr8-v49w-3333
fix available vianpm audit fix --force
Will install sweetalert2@11.6.13, which is a breaking change
node_modules/sweetalert2
1 low severity vulnerability
To address all issues (including breaking changes), run:
npm audit fix --force
but npm audit fix --force doesn't help
I try to use npm run dev and npm run watch too.
Edit:
I add this to app.blade.php
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
And it's help.
But, Can it be made to work without it?
英文:
I can't have problem w sweetalert2.
I have error in console:
> Uncaught ReferenceError: Swal is not defined
at HTMLButtonElement.<anonymous> (list:121:13)
at HTMLButtonElement.dispatch (jquery-3.7.0.js:5135:27)
at elemData.handle (jquery-3.7.0.js:4939:28)
It concerns this part of code (index.blade.php):
<script type="text/javascript">
$(function() {
$('.delete').click(function() {
Swal.fire("hello");
});
});
</script>
In others files I have:
app.blade.php:
<script type="text/javascript">
@yield('javascript')
</script>
bootstap.js
import 'bootstrap';
try {
window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
window.Swal = require('sweetalert2');
require('bootstrap');
} catch (e) {}
package.json
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"watch": "vite build --watch",
"prod": "vite production"
},
"devDependencies": {
"@popperjs/core": "^2.11.6",
"axios": "^1.1.2",
"bootstrap": "^5.2.3",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.56.1",
"vite": "^4.0.0"
},
"dependencies": {
"jquery": "^3.7.0",
"popper.js": "^1.16.1",
"sweetalert2": "^11.7.16"
}
}
app.scss
@import 'sweetalert2/src/sweetalert2.scss';
I install sweetalert2 using command:
> npm install sweetalert2
And this add new folder sweetalert in node_modules
When I use npm audit I have:
> npm audit report
sweetalert2 >=11.6.14
sweetalert2 v11.6.14 and above contains potentially undesirable behavior - https://github.com/advisories/GHSA-mrr8-v49w-3333
fix available via `npm audit fix --force`
Will install sweetalert2@11.6.13, which is a breaking change
node_modules/sweetalert2
1 low severity vulnerability
To address all issues (including breaking changes), run:
npm audit fix --force
but npm audit fix --force doesn't help
I try to use npm run dev and npm run watch too.
Edit:
I add this to app.blade.php
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
And it's help.
But, Can it be made to work without it?
答案1
得分: 1
使用导入。
**bootstrap.js**
import jQuery from "jquery";
window.$ = jQuery;
import {popper} from "@popperjs/core";
window.popper = popper;
import {swal} from "sweetalert2";
window.swal = swal;
英文:
Use imports.
bootstrap.js
import jQuery from "jquery";
window.$ = jQuery;
import {popper} from "@popperjs/core";
window.popper = popper;
import {swal} from "sweetalert2";
window.swal = swal;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论