Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

调整Tabs和Drawer的beforeRemove/beforeClose处理 #688

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/routers/drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@
title: '关闭确认',
content: '您确认要关闭抽屉吗?',
onOk: () => {
resolve();
resolve(true);
},
onCancel: () => {
reject();
resolve(false);
}
});
});
Expand Down
15 changes: 10 additions & 5 deletions src/components/drawer/drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,17 @@
}

const before = this.beforeClose();
if (!before) { // sync function returned falsy, don't close
return;
}

if (before && before.then) {
before.then(() => {
this.handleClose();
if (before.then) { // promise
before.then((result) => {
if (result) { // promise resolved truthy
this.handleClose();
}
});
} else {
} else { // sync returned truthy
this.handleClose();
}
},
Expand Down Expand Up @@ -309,4 +314,4 @@
}
}
};
</script>
</script>
13 changes: 9 additions & 4 deletions src/components/tabs/tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,17 @@
}

const before = this.beforeRemove(index);
if (!before) { // returned falsy, don't close tab
return;
}

if (before && before.then) {
before.then(() => {
this.handleRemoveTab(index);
if (before.then) { // promise
before.then((result) => {
if (result) { // promise resolved truthy
this.handleRemoveTab(index);
}
});
} else {
} else { // sync returned truthy
this.handleRemoveTab(index);
}
},
Expand Down
Loading