mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-05 07:29:46 +08:00
docs(Toast): use setup
This commit is contained in:
parent
775f0bef47
commit
06f8c19660
@ -31,8 +31,10 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
i18n: {
|
||||
import { useTranslate } from '@demo/use-translate';
|
||||
import Toast from '..';
|
||||
|
||||
const i18n = {
|
||||
'zh-CN': {
|
||||
fail: '失败提示',
|
||||
text: '提示内容',
|
||||
@ -69,71 +71,86 @@ export default {
|
||||
positionBottom: 'Bottom',
|
||||
customPosition: 'Custom Position',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
methods: {
|
||||
showLoadingToast(loadingType) {
|
||||
this.$toast.loading({
|
||||
export default {
|
||||
setup() {
|
||||
const t = useTranslate(i18n);
|
||||
|
||||
const showLoadingToast = (loadingType) => {
|
||||
Toast.loading({
|
||||
forbidClick: true,
|
||||
message: this.t('loading'),
|
||||
message: t('loading'),
|
||||
loadingType,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showSuccessToast() {
|
||||
this.$toast.success(this.t('text2'));
|
||||
},
|
||||
const showSuccessToast = () => {
|
||||
Toast.success(t('text2'));
|
||||
};
|
||||
|
||||
showFailToast() {
|
||||
this.$toast.fail(this.t('text3'));
|
||||
},
|
||||
const showFailToast = () => {
|
||||
Toast.fail(t('text3'));
|
||||
};
|
||||
|
||||
showTopToast() {
|
||||
this.$toast({
|
||||
message: this.t('positionTop'),
|
||||
const showTopToast = () => {
|
||||
Toast({
|
||||
message: t('positionTop'),
|
||||
position: 'top',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showBottomToast() {
|
||||
this.$toast({
|
||||
message: this.t('positionBottom'),
|
||||
const showBottomToast = () => {
|
||||
Toast({
|
||||
message: t('positionBottom'),
|
||||
position: 'bottom',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showIconToast() {
|
||||
this.$toast({
|
||||
message: this.t('customIcon'),
|
||||
const showIconToast = () => {
|
||||
Toast({
|
||||
message: t('customIcon'),
|
||||
icon: 'like-o',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showImageToast() {
|
||||
this.$toast({
|
||||
message: this.t('customImage'),
|
||||
const showImageToast = () => {
|
||||
Toast({
|
||||
message: t('customImage'),
|
||||
icon: 'https://img.yzcdn.cn/vant/logo.png',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showCustomizedToast() {
|
||||
const toast = this.$toast.loading({
|
||||
const showCustomizedToast = () => {
|
||||
const toast = Toast.loading({
|
||||
duration: 0,
|
||||
forbidClick: true,
|
||||
message: this.t('text4', 3),
|
||||
message: t('text4', 3),
|
||||
});
|
||||
|
||||
let second = 3;
|
||||
const timer = setInterval(() => {
|
||||
second--;
|
||||
if (second) {
|
||||
toast.message = this.t('text4', second);
|
||||
toast.message = t('text4', second);
|
||||
} else {
|
||||
clearInterval(timer);
|
||||
this.$toast.clear();
|
||||
Toast.clear();
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
t,
|
||||
showTopToast,
|
||||
showFailToast,
|
||||
showIconToast,
|
||||
showImageToast,
|
||||
showBottomToast,
|
||||
showLoadingToast,
|
||||
showSuccessToast,
|
||||
showCustomizedToast,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user