mirror of
https://github.com/youzan/vant.git
synced 2025-10-22 03:44:48 +00:00
Merge branch 'hotfix/fix_toast_0330' into 'master'
feat: 简化toast为单个intance See merge request !20
This commit is contained in:
@@ -2,24 +2,17 @@ import Vue from 'vue';
|
||||
import merge from 'src/utils/merge';
|
||||
|
||||
const ToastConstructor = Vue.extend(require('./toast.vue'));
|
||||
let toastQueue = [];
|
||||
let instance;
|
||||
|
||||
const getInstance = () => {
|
||||
if (toastQueue.length > 0) {
|
||||
const instance = toastQueue[0];
|
||||
toastQueue.splice(0, 1);
|
||||
return instance;
|
||||
}
|
||||
return new ToastConstructor({
|
||||
if (instance) instance.clear();
|
||||
|
||||
instance = new ToastConstructor({
|
||||
el: document.createElement('div')
|
||||
});
|
||||
return instance;
|
||||
};
|
||||
|
||||
const returnInstance = instance => {
|
||||
if (instance) {
|
||||
toastQueue.push(instance);
|
||||
}
|
||||
};
|
||||
|
||||
const removeDom = event => {
|
||||
if (event.target.parentNode) {
|
||||
@@ -31,7 +24,6 @@ var Toast = (options = {}) => {
|
||||
const duration = options.duration || 3000;
|
||||
|
||||
let instance = getInstance();
|
||||
returnInstance(instance);
|
||||
instance.closed = false;
|
||||
clearTimeout(instance.timer);
|
||||
instance.type = options.type ? options.type : 'text';
|
||||
@@ -77,4 +69,8 @@ Toast.fail = (options) => {
|
||||
}, options));
|
||||
};
|
||||
|
||||
Toast.clear = () => {
|
||||
if (instance) instance.clear();
|
||||
}
|
||||
|
||||
export default Toast;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<transition name="zan-toast">
|
||||
<transition name="zan-toast-fade">
|
||||
<div class="zan-toast-wrapper" v-show="visible">
|
||||
<div class="zan-toast" :class="['zan-toast--' + displayStyle]">
|
||||
<!-- 只显示文字 -->
|
||||
|
@@ -44,9 +44,13 @@
|
||||
}
|
||||
|
||||
.zan-toast__text {
|
||||
padding-bottom: 20px;
|
||||
padding: 15px 0 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.zan-toast-fade-enter, .zan-toast-fade-leave-active {
|
||||
opacity: 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user