mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs(Dialog): use composition api
This commit is contained in:
parent
8a7882b0c8
commit
488deefb30
@ -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 };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -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 };
|
||||||
};
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user