mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: 简化toast为单个intance
This commit is contained in:
parent
50d87fa634
commit
9e0a6bb984
@ -39,6 +39,11 @@ export default {
|
||||
message: leftSec.toString()
|
||||
});
|
||||
window.setInterval(() => {
|
||||
if (leftSec <= 0) {
|
||||
window.clearInterval();
|
||||
toast.clear();
|
||||
return;
|
||||
}
|
||||
if (leftSec <= 1) {
|
||||
window.clearInterval();
|
||||
toast.message = '跳转中...'
|
||||
|
@ -2,24 +2,18 @@ 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;
|
||||
if (instance) {
|
||||
instance.clear();
|
||||
}
|
||||
return new ToastConstructor({
|
||||
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 +25,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';
|
||||
|
@ -44,7 +44,7 @@
|
||||
}
|
||||
|
||||
.zan-toast__text {
|
||||
padding-bottom: 20px;
|
||||
padding: 15px 0 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user