mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
* [bugfix] Checkbox border render error in weixin browser * [bugfix] TreeSelect dependency path error * [bugfix] Swipe should clear autoplay timer when destroyed * [bugfix] Optimize component dependency analyze when build style entry * merge * update yarn.lock * update README.md * update README.md * update README.md * update README.md * update README.md * [Doc] add more badges in README.md * update README.md * [bugfix] Address & Contact list style * fix: contact test cases * [bugfix] popup style missing when build style entry * [bugfix] Search: onSearch event arguments missing * [Doc] add demo pages * update zan-doc@0.3.7 * fix: build entry error * [Doc] add goods demo * [bugfix] button primary background color * [Doc] update doc detail * [new feature] Coupon add 'showExchangeBar' prop && add empty style * [new feature] Toast support `position` prop * [new feature] Tabbar add 'info' prop
59 lines
1.2 KiB
JavaScript
59 lines
1.2 KiB
JavaScript
import Vue from 'vue';
|
|
import VueToast from './toast';
|
|
|
|
let instance;
|
|
|
|
const defaultOptions = {
|
|
visible: true,
|
|
type: 'text',
|
|
position: 'middle',
|
|
duration: 3000,
|
|
forbidClick: false,
|
|
clear: () => {
|
|
instance.visible = false;
|
|
}
|
|
};
|
|
|
|
const createInstance = () => {
|
|
if (!instance) {
|
|
const ToastConstructor = Vue.extend(VueToast);
|
|
instance = new ToastConstructor({
|
|
el: document.createElement('div')
|
|
});
|
|
document.body.appendChild(instance.$el);
|
|
}
|
|
};
|
|
|
|
const Toast = (options = {}) => {
|
|
createInstance();
|
|
|
|
options = typeof options === 'string' ? { message: options } : options;
|
|
options = { ...defaultOptions, ...options };
|
|
Object.assign(instance, options);
|
|
|
|
clearTimeout(instance.timer);
|
|
|
|
if (options.duration !== 0) {
|
|
instance.timer = setTimeout(() => {
|
|
instance.clear();
|
|
}, options.duration);
|
|
}
|
|
|
|
return instance;
|
|
};
|
|
|
|
const createMethod = type => (options = {}) => Toast({
|
|
type,
|
|
message: typeof options === 'string' ? options : options.message,
|
|
...options
|
|
});
|
|
|
|
Toast.loading = createMethod('loading');
|
|
Toast.success = createMethod('success');
|
|
Toast.fail = createMethod('fail');
|
|
Toast.clear = () => {
|
|
instance && instance.clear();
|
|
};
|
|
|
|
export default Toast;
|