docs(Dialog): use composition api

This commit is contained in:
chenjiahan 2020-12-09 17:52:31 +08:00
parent 8a7882b0c8
commit 488deefb30
3 changed files with 57 additions and 45 deletions

View File

@ -111,11 +111,12 @@ If you need to render vue components within a dialog, you can use dialog compone
``` ```
```js ```js
import { ref } from 'vue';
export default { export default {
data() { setup() {
return { const show = ref(false);
show: false, return { show };
};
}, },
}; };
``` ```

View File

@ -144,11 +144,12 @@ export default {
``` ```
```js ```js
import { ref } from 'vue';
export default { export default {
data() { setup() {
return { const show = ref(false);
show: false, return { show };
};
}, },
}; };
``` ```

View File

@ -28,6 +28,10 @@
</template> </template>
<script> <script>
import { ref } from 'vue';
import { useTranslate } from '../../composables/use-translate';
import Dialog from '..';
export default { export default {
i18n: { i18n: {
'zh-CN': { 'zh-CN': {
@ -49,62 +53,68 @@ export default {
}, },
}, },
data() { setup() {
return { const t = useTranslate();
show: false, const show = ref(false);
currentRate: 0,
image: 'https://img.yzcdn.cn/vant/apple-3.jpg', const onClickAlert = () => {
Dialog.alert({
title: t('title'),
message: t('content'),
});
}; };
},
methods: { const onClickAlert2 = () => {
onClickAlert() { Dialog.alert({
this.$dialog.alert({ message: t('content'),
title: this.t('title'),
message: this.t('content'),
}); });
}, };
onClickAlert2() { const onClickRound = () => {
this.$dialog.alert({ Dialog.alert({
message: this.t('content'),
});
},
onClickRound() {
this.$dialog.alert({
theme: 'round-button', theme: 'round-button',
title: this.t('title'), title: t('title'),
message: this.t('content'), message: t('content'),
}); });
}, };
onClickRound2() { const onClickRound2 = () => {
this.$dialog.alert({ Dialog.alert({
theme: 'round-button', theme: 'round-button',
message: this.t('content'), message: t('content'),
}); });
}, };
onClickConfirm() { const onClickConfirm = () => {
this.$dialog.confirm({ Dialog.confirm({
title: this.t('title'), title: t('title'),
message: this.t('content'), message: t('content'),
}); });
}, };
onClickBeforeClose() { const onClickBeforeClose = () => {
const beforeClose = (action) => const beforeClose = (action) =>
new Promise((resolve) => { new Promise((resolve) => {
setTimeout(() => resolve(action === 'confirm'), 1000); setTimeout(() => resolve(action === 'confirm'), 1000);
}); });
this.$dialog.confirm({ Dialog.confirm({
title: this.t('title'), title: t('title'),
message: this.t('content'), message: t('content'),
beforeClose, beforeClose,
}); });
}, };
return {
show,
image: 'https://img.yzcdn.cn/vant/apple-3.jpg',
onClickAlert,
onClickAlert2,
onClickRound,
onClickRound2,
onClickConfirm,
onClickBeforeClose,
};
}, },
}; };
</script> </script>