[Improvement] Dialog: add before-close prop (#881)

This commit is contained in:
neverland
2018-04-17 14:16:28 +08:00
committed by GitHub
parent f87dd825d7
commit 6d74198e27
7 changed files with 82 additions and 51 deletions

View File

@@ -13,7 +13,8 @@
<van-button @click="show = true">{{ $t('advancedUsage') }}</van-button>
<van-dialog
v-model="show"
:asyncConfirm="onClickConfirmAsync"
show-cancel-button
:before-close="beforeClose"
>
<van-field
v-model="username"
@@ -59,7 +60,7 @@ export default {
Dialog.alert({
title: this.$t('title'),
message: this.$t('content')
})
});
},
onClickAlert2() {
@@ -75,12 +76,12 @@ export default {
});
},
onClickConfirmAsync() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 1000)
})
beforeClose(action, done) {
if (action === 'confirm') {
setTimeout(done, 1000);
} else {
done();
}
}
}
};

View File

@@ -77,6 +77,7 @@ export default {
| overlay | Whether to show overlay | `Boolean` | `true` | - |
| closeOnClickOverlay | Whether to close when click overlay | `Boolean` | `false` | - |
| lockScroll | Whether to lock body scroll | `Boolean` | `true` | - |
| beforeClose | Callback before closecall done to close dialog | (action: string, done: function) => void | - | - |
#### Advanced Usage
If you need to render vue components within a dialog, you can use dialog component.
@@ -110,12 +111,12 @@ export default {
},
methods: {
onClickConfirmAsync() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 1000)
})
beforeClose() {
if (action === 'confirm') {
setTimeout(done, 1000);
} else {
done();
}
}
}
}
@@ -136,6 +137,7 @@ export default {
| overlay | Whether to show overlay | `Boolean` | `true` | - |
| close-on-click-overlay | Whether to close when click overlay | `Boolean` | `false` | - |
| lock-scroll | Whether to lock background scroll | `Boolean` | `true` | - |
| before-close | Callback before closecall done to close dialog | (action: string, done: function) => void | - | - |
### Event

View File

@@ -78,13 +78,18 @@ export default {
| overlay | 是否展示蒙层 | `Boolean` | `true` | - |
| closeOnClickOverlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` | - |
| lockScroll | 是否锁定背景滚动 | `Boolean` | `true` | - |
| beforeClose | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - | - |
#### 高级用法
如果需要在弹窗内实现更复杂的交互,可以通过组件形式来调用 Dialog
```html
<van-dialog v-model="show" :asyncConfirm="onClickConfirmAsync">
<van-dialog
v-model="show"
show-cancel-button
:before-close="beforeClose"
>
<van-field
v-model="username"
label="用户名"
@@ -112,12 +117,12 @@ export default {
},
methods: {
onClickConfirmAsync() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 1000)
});
beforeClose() {
if (action === 'confirm') {
setTimeout(done, 1000);
} else {
done();
}
}
}
}
@@ -130,7 +135,6 @@ export default {
| v-model | 是否显示弹窗 | `Boolean` | - | - |
| title | 标题 | `String` | - | - |
| message | 内容 | `String` | - | - |
| async-confirm | dialog是否异步关闭传入一个返回Promise的函数在点击确定时触发。 | `Function` | - | - |
| show-confirm-button | 是否展示确认按钮 | `Boolean` | `true` | - |
| show-cancel-button | 是否展示取消按钮 | `Boolean` | `false` | - |
| confirm-button-text | 确认按钮的文案 | `String` | `确认` | - |
@@ -138,6 +142,7 @@ export default {
| overlay | 是否展示蒙层 | `Boolean` | `true` | - |
| close-on-click-overlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` | - |
| lock-scroll | 是否锁定背景滚动 | `Boolean` | `true` | - |
| before-close | 关闭前的回调函数,调用 done 后关闭弹窗 | (action: string, done: function) => void | - | - |
### Event