Vue js 中使用 Sweetalert2 删除确认

Yos*_*sef -1 javascript laravel vue.js sweetalert2

我试图制作一个 sweetalert,当用户单击删除按钮时,它将触发一个 sweetalert,当用户单击时,Yes, Delete it!它应该发出 axois 请求来删除状态。当用户单击Yes, Delete it!sweetalert 时,它会关闭,但从未发出请求。如果我删除 sweetalert 并仅留下请求,它将删除该记录。

删除按钮

<button @click="destroy(statuses.id)" class="btn btn-danger btn-flat btn-sm"> <i class="fa fa-remove"></i> </button>
Run Code Online (Sandbox Code Playgroud)

删除方法

methods: {
            destroy(id) {
                swal({
                    title: "Delete this order status?",
                    text: "Are you sure? You won't be able to revert this!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    confirmButtonText: "Yes, Delete it!",
                }, () => {
                    del('status-delete/' + id)
                })
            }
        }
Run Code Online (Sandbox Code Playgroud)

Wre*_*igh 5

根据文档,您可以执行此操作。

swal({
    title: "Delete this order status?",
    text: "Are you sure? You won't be able to revert this!",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#3085d6",
    confirmButtonText: "Yes, Delete it!"
}).then((result) => { // <--
    if (result.value) { // <-- if confirmed
        del('status-delete/' + id);
    }
});
Run Code Online (Sandbox Code Playgroud)

参考: https: //sweetalert2.github.io/