Closed zhuokuang closed 9 months ago
通过函数式调用弹出 toast 之后,立马调用 hide 方法或者通过 Promise.resolve().then 调用 hide 方法,toast 不会隐藏。
通过函数调用弹出 toast 时,并不会立即将 toast 的 show 属性设置为 true,而是会在定时器中将 show 属性设置为 true,此时如果立即通过 hide 方法关闭 toast,在下一轮事件循环中,还是会将 show 设置为 true,toast 也不会被关闭。
在调用 hide 时,也使用定时器将 show 设置为 false。
问题:
通过函数式调用弹出 toast 之后,立马调用 hide 方法或者通过 Promise.resolve().then 调用 hide 方法,toast 不会隐藏。
原因:
通过函数调用弹出 toast 时,并不会立即将 toast 的 show 属性设置为 true,而是会在定时器中将 show 属性设置为 true,此时如果立即通过 hide 方法关闭 toast,在下一轮事件循环中,还是会将 show 设置为 true,toast 也不会被关闭。
截图:
解决:
在调用 hide 时,也使用定时器将 show 设置为 false。