mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-25 11:06:45 +08:00
修复 toast 未传入 timeout 时不会自动关闭的问题 (#361)
This commit is contained in:
parent
12d7dcf7e9
commit
e739520290
@ -1,4 +1,5 @@
|
|||||||
const TOAST_CONFIG_KEY = 'zanui.__zanToastPageConfig';
|
const TOAST_CONFIG_KEY = 'zanui.__zanToastPageConfig';
|
||||||
|
const DEFAULT_SHOW_TOAST_TIME = 3000;
|
||||||
|
|
||||||
let timeoutData = {
|
let timeoutData = {
|
||||||
timeoutId: 0,
|
timeoutId: 0,
|
||||||
@ -58,11 +59,13 @@ function Toast(optionsOrMsg, pageCtx) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let timeoutId = 0;
|
let timeoutId = 0;
|
||||||
|
// toast 计时,如果小于0,就不会去关闭。
|
||||||
if (parsedOptions.timeout >= 0) {
|
// 如果不传,就取默认值
|
||||||
|
const timeoutOption = parsedOptions.timeout || DEFAULT_SHOW_TOAST_TIME;
|
||||||
|
if (timeoutOption >= 0) {
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
toastCtx.clear();
|
toastCtx.clear();
|
||||||
}, parsedOptions.timeout || 3000);
|
}, timeoutOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ Toast.setDefaultOptions = function (options = {}, type = 'page') {
|
|||||||
type: options.type || '',
|
type: options.type || '',
|
||||||
icon: options.icon || '',
|
icon: options.icon || '',
|
||||||
image: options.image || '',
|
image: options.image || '',
|
||||||
timeout: options.timeout || 3000
|
timeout: options.timeout || DEFAULT_SHOW_TOAST_TIME
|
||||||
};
|
};
|
||||||
|
|
||||||
if (type === 'global') {
|
if (type === 'global') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user