ZBLOG

Cancel

为了在确认操作完成后返回上一页,你可以在 handleConfirm 函数中调用浏览器的历史 API 或 Vue Router 的导航方法来实现这一功能。下面是如何修改 handleConfirm 方法,以便在成功提交之后返回到上一页。

修改后的代码

const handleConfirm = () => {
  singleCustomerTags({
    tagsId: targetKeys.value,
    customerId: custId.value,
    customerName: name.value
  }).then((response) => {
    if (response.success) {
      message.success(response.message);
      // 在这里添加返回上一页的逻辑
      window.parent.postMessage({ type: 'close-dialog', action: 'confirm' });
    } else {
      message.error(response.message);
    }
  });
};

完整代码段

将你的 handleConfirm 函数替换为上面的版本,这样当你点击“确认”按钮,并且请求成功时,消息会显示完成,然后通过发送一个消息给父窗口来关闭对话框或进行相应处理(例如,返回到上一个页面)。

如果使用 Vue Router

如果想直接利用 Vue Router 跳转,可以这样做:

import { useRouter } from 'vue-router';

// 在脚本顶部引入 router
const router = useRouter();

const handleConfirm = () => {
  singleCustomerTags({
    tagsId: targetKeys.value,
    customerId: custId.value,
    customerName: name.value
  }).then((response) => {
    if (response.success) {
      message.success(response.message);
      
      // 使用 router 返回到上一页
      router.back();
      
    } else {
      message.error(response.message);
    }
  });
};

通过这种方式,你可以确保在确认操作后返回到之前的页面,无论是通过关闭对话框还是使用 Vue Router 的方法。根据你的具体需求选择适合的方法。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:http://sdn.0voice.com/?id=7464

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?