Reactjs 在react js中实现删除按钮的甜警报?

Reactjs 在react js中实现删除按钮的甜警报?,reactjs,Reactjs,我想在我的项目中的delete按钮上实现一种甜警报。在标签aI中 onClick={()=>{props.deleteHandle(props.data.code)}} 代码是我的变量 我用这个函数作为道具 我的定义如下: deleteHandle = (code) => { let self = this; swal({ title: "Are you sure you want to delet this item?",

我想在我的项目中的delete按钮上实现一种甜警报。在标签
a
I中

onClick={()=>{props.deleteHandle(props.data.code)}}

代码是我的变量

我用这个函数作为道具

我的定义如下:

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安装sweetalert——保存

我还导入了swal库,如下所示:
从“sweetalert”导入swal

但是,“删除”按钮不起作用。但我从它的功能中删除了swal。 我试图找出我的问题,但我不明白。 有人能帮我吗?
谢谢。

我通过删除swal的第二个参数解决了这个问题,并将它放在promise中。然后(async=>{…})。

谢谢你编辑这个问题。它怎么不起作用?您是否收到一些错误?是的,仍然不工作,我删除了显示的swal alert的第二个参数,然后我将第二个参数async()=>,然后它就不起作用了,我也删除了swal delete按钮,但没有发出sweet警报。下面是错误消息:未捕获的sweet警报:意外的第二个参数(async()=>{let url=
/api/v1/wiki/admin/delete?wikiCode=${code}
;if(self.state.type==“faq”){url=
/api/v1/faq/admin/delete?faqCode=${code}
;}if(self.state.type==“chapters”){url=
/api/v1/ch/admin/delete?chapterCode=${code}
}等待{u-utils}hbes}网页包{u-WEBPACK}导入的模块{u-10}[“default”]。获取(url,{headers:{“内容类型”:“应用程序/json”,授权:
承载${window localStorage.getItem('access\u-token});self.state.type)})错误告诉您第二个参数是意外的。