1.引入js
NPM/Yarn
NPM combined with a tool like Browserify or Webpack is the recommended method of installing SweetAlert.
(1)
npm install sweetalert --save
then, simply import it into your application:
(2)
import swal from 'sweetalert';
CDN
You can also find SweetAlert on unpkg and jsDelivr and use the global swal variable.
<script src="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
1.简单提示
swal("Hello world!");
2.删除提示
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
} else {
swal("Your imaginary file is safe!");
}
});