我认为我必须以某种方式导入这个错误,但我不确定。我按照github上的说明进行操作。它说我可以npm install
,然后就可以了import swal from 'sweetalert2'
。我还必须使用js
和css
文件吗?
这是我的代码:
import React, { Component } from 'react';
import swal from 'sweetalert2';
class TestSwal extends Component {
componentDidMount() {
swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, keep it'
}).then(
function() {
swal('Deleted!', 'Your imaginary file has been deleted.', 'success');
},
function(dismiss) {
// dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
if (dismiss === 'cancel') {
swal('Cancelled', 'Your imaginary file is safe :)', 'error');
}
}
);
}
render() {
return <div>Test Swal</div>;
}
}
export default TestSwal;