Yao 1d7c23b289
[refactor] Toast: 升级为自定义组件 (#191)
* toast 组件初始化

* toast 增加示例 && 逻辑补全

* toast 支持直接 loading 调用

* 增加 toast readme

* 去除多余的引用
2018-04-12 21:58:54 +08:00

41 lines
637 B
JavaScript

const DEFAULT_DATA = {
show: false,
message: '',
icon: '',
image: '',
mask: false
};
const SUPPORT_TYPE = ['loading', 'success', 'fail'];
Component({
data: {
...DEFAULT_DATA
},
methods: {
show(options) {
const toastOptions = { ...options };
let icon = options.icon || '';
let image = options.image || '';
if (SUPPORT_TYPE.indexOf(options.type) > -1) {
icon = options.type;
image = '';
}
this.setData({
...toastOptions,
icon,
image
});
},
clear() {
this.setData({
...DEFAULT_DATA
});
}
}
});