diff --git a/packages/vant/src/dialog/function-call.tsx b/packages/vant/src/dialog/function-call.tsx index ae1764e5e..79f794aeb 100644 --- a/packages/vant/src/dialog/function-call.tsx +++ b/packages/vant/src/dialog/function-call.tsx @@ -46,10 +46,12 @@ function initInstance() { ({ instance } = mountComponent(Wrapper)); } -export function showDialog(options: DialogOptions) { +export function showDialog( + options: DialogOptions, +): Promise { /* istanbul ignore if */ if (!inBrowser) { - return Promise.resolve(); + return Promise.resolve(undefined); } return new Promise((resolve, reject) => { @@ -59,7 +61,7 @@ export function showDialog(options: DialogOptions) { instance.open( extend({}, currentOptions, options, { - callback: (action: DialogAction) => { + callback: (action?: DialogAction) => { (action === 'confirm' ? resolve : reject)(action); }, }), diff --git a/packages/vant/src/swipe-cell/README.md b/packages/vant/src/swipe-cell/README.md index 37e7c9b2f..038ce1691 100644 --- a/packages/vant/src/swipe-cell/README.md +++ b/packages/vant/src/swipe-cell/README.md @@ -92,8 +92,8 @@ export default { showConfirmDialog({ title: 'Are you sure to delete?', }) - .then(resolve) - .catch(resolve); + .then(() => resolve(true)) + .catch(() => resolve(false)); }); } }; diff --git a/packages/vant/src/swipe-cell/README.zh-CN.md b/packages/vant/src/swipe-cell/README.zh-CN.md index e3dec9713..afade0035 100644 --- a/packages/vant/src/swipe-cell/README.zh-CN.md +++ b/packages/vant/src/swipe-cell/README.zh-CN.md @@ -99,8 +99,8 @@ export default { showConfirmDialog({ title: '确定删除吗?', }) - .then(resolve) - .catch(resolve); + .then(() => resolve(true)) + .catch(() => resolve(false)); }); } }; diff --git a/packages/vant/src/swipe-cell/demo/index.vue b/packages/vant/src/swipe-cell/demo/index.vue index 25a433043..23e16927c 100644 --- a/packages/vant/src/swipe-cell/demo/index.vue +++ b/packages/vant/src/swipe-cell/demo/index.vue @@ -38,9 +38,13 @@ const beforeClose = ({ position }: { position: string }) => { case 'outside': return true; case 'right': - return showConfirmDialog({ - title: t('confirm'), - }) as Promise; + return new Promise((resolve) => { + showConfirmDialog({ + title: t('confirm'), + }) + .then(() => resolve(true)) + .catch(() => resolve(false)); + }); } };