An Issue in wx.showToast

Translation Notice
This article was machine-translated using DeepSeek-R1.

  • Original Version: Authored in Chinese by myself
  • Accuracy Advisory: Potential discrepancies may exist between translations
  • Precedence: The Chinese text shall prevail in case of ambiguity
  • Feedback: Technical suggestions regarding translation quality are welcomed
1
2
3
4
5
6
wx.showToast({
    title: 'Success',
    icon: 'fail',
    duration: 2000,
    success: func
})
1
2
3
4
5
6
7
8
wx.showToast({
    title: 'Success',
    icon: 'fail',
    duration: 2000,
    success: res => {
        func()
    }
})

Why do both code snippets execute func “immediately”?

Because the success callback is called as soon as the toast is successfully displayed. To execute func after duration milliseconds, use:

1
2
3
4
5
6
wx.showToast({
    title: 'Success',
    icon: 'fail',
    duration: 2000,
})
setTimeout(func, 2000)
Built with Hugo
Theme Stack designed by Jimmy