fix(Toast): 修复Toast组件对timeout小于0的支持 @rex-zsd (#340)

#339
This commit is contained in:
rex 2018-07-08 14:39:29 +08:00 committed by Yao
parent 3af67f5565
commit 222084f704
4 changed files with 21 additions and 4 deletions

View File

@ -42,6 +42,14 @@ Page({
});
},
showEverToast() {
Toast({
message: 'toast的内容',
selector: '#zan-toast-test',
timeout: -1
});
},
showLoading() {
Toast.loading({
message: '加载中',

View File

@ -25,6 +25,10 @@
只显示图标的toast
</zan-button>
<zan-button bind:btnclick="showEverToast">
不消失的的toast
</zan-button>
<zan-button bind:btnclick="showLoading">
显示 Loading
</zan-button>

View File

@ -52,4 +52,4 @@ Toast.loading({
| type | 提示类型 | String | - | loading success fail |
| icon | toast 显示图标,可以用 icon 里面支持的所有图标 | String | - | - |
| image | toast 显示图标,为图片的链接,传入此值后会覆盖 icon 值 | String | - | |
| timeout | toast 显示时间小于0则会一直显示需要手动调用 clearZanToast 清除 | Number | - | |
| timeout | toast 显示时间小于0则会一直显示需要手动调用 Toast.clear 清除 | Number | - | |

View File

@ -57,9 +57,14 @@ function Toast(optionsOrMsg, pageCtx) {
show: true
});
const timeoutId = setTimeout(() => {
toastCtx.clear();
}, parsedOptions.timeout || 3000);
let timeoutId = 0;
if (parsedOptions.timeout >= 0) {
timeoutId = setTimeout(() => {
toastCtx.clear();
}, parsedOptions.timeout || 3000);
}
timeoutData = {
timeoutId,