首页 > 解决方案 > 如何在重定向之前显示确认警报?

问题描述

如何在重定向之前显示 swal fire 警报?

<a :href="`/public/project/sendalert/${project.id}`">{project.first_name+' '+project.last_name}} @click="Alert"</a></strong></span>
    alert() {
            window.Swal.fire({
                title: 'Are you sure?',
                text: "Are you sure?"
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'YES!',
              })
      },

标签: javascriptvue.jssweetalert

解决方案


1.click事件应该放入属性中。

<a @click="Alert">{project.first_name+' '+project.last_name}}</a></strong></span>

2.对确认操作执行重定向。

alert() {
    window.Swal.fire({
        title: 'Are you sure?',
        text: "Are you sure?",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'YES!',
    }, function (isConfirm) {
        if (isConfirm) {
            location.href = "...";
        }
    });
}

推荐阅读