我想在我的项目中的删除按钮上实现一种甜蜜的警报。在标签a
中,我放置
onClick = {() => {props.deleteHandle(props.data.code)}}
代码是我的变量。
我用这个功能作为道具。
i定义如下:
deleteHandle = (code) => {
let self = this;
swal({
title: "Are you sure you want to delet this item?",
text: "You will not be able to recover your data!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: false
}, async () => {
let url = `/api/v1/wiki/admin/delete?wCode=${code}`;
if (self.state.type === "faqs") {
url = `/api/v1/faq/admin/delete?fCode=${code}`
}
if (self.state.type === "chapters") {
url = `/api/v1/ch/admin/delete?chCode=${code}`
}
await baseUrl.get(url, {
headers: {
"content-type": "application/json",
Authorization: `Bearer ${window.localStorage.getItem('access_token')}`,
},
});
self.fetchData(self.state.type);
});
}
我通过npm install sweetalert --save
安装了swal我还导入了swal库,如下所示:import swal from 'sweetalert';
但是,删除按钮不起作用。但我把swal从它的功能中删除了。我试图弄清楚我的问题,但我不能理解。有人能帮我吗?谢谢
我通过删除swal的第二个参数来解决问题,并将其放入promise中。然后(async=>{…}(.