wx.showToast() 在真机中一闪而过

31 篇文章 0 订阅
31 篇文章 0 订阅
// 发送请求
		uni.request({
			// 请求类型
			method: type,
			// 请求地址
			url: baseApi + url,
			// 请求参数
			data: data,
			// 请求头配置
			header: header,
			// 数据格式
			dataType: 'json',
		}).then((response) => {
			// 如果请求成功
			// 关闭加载loading
			setTimeout(function () {
				uni.hideLoading();
			}, 0);
			let [error, res] = response;
			resolve(res.data);
		}).catch(error => {
			// 如果请求错误,关闭加载loading
			setTimeout(function () {
				uni.hideLoading();
			}, 0);
			let [err, res] = error;
			reject(err)
		})
	});
解决办法:
	setTimeout(() => {
						wx.showToast({
							icon: 'none',
							title: `${retult.msg}`,
							duration: 3000
						})
					}, 100)

为啥真机中一闪而过 因为uni.hideLoading();和wx.showToast用的同一个框子底层,解决办法还是用异步执行顺序来

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
真机上,uni.showToast一闪而过的现象可能是由于代码的执行顺序所造成的。根据引用[2]的描述,wx.showToastwx.hideToast应该配对使用。如果在真机上遇到uni.showToast一闪而过的情况,可能是因为uni.showLoading和uni.showToast之间的执行顺序不正确,导致toast框在loading框未完全隐藏之前就被隐藏了。一种解决方案是在uni.showToast之前加入适当的延迟,确保uni.showLoading完全隐藏后再调用uni.showToast。例如,可以使用setTimeout来延迟调用uni.showToast,确保它在uni.hideLoading之后执行,如下所示: ``` uni.showLoading(); setTimeout(() => { uni.showToast({ title: '编辑成功', icon: 'none', duration: 1000, mask: true }); }, 1000); ``` 这样做可以确保toast框在loading框完全隐藏后再显示,避免了uni.showToast一闪而过的情况发生。另外,根据引用的描述,uni.showLoading和uni.showToast是调用同一个框,都受uni.hideLoading或uni.hideToast的影响。因此,如果仍然遇到toast框闪烁一下就消失的问题,可以尝试在uni.hideLoading之后加入适当的延迟,如下所示: ``` uni.showLoading(); uni.hideLoading(); setTimeout(() => { uni.showToast({ title: '编辑成功', icon: 'none', duration: 1000, mask: true }); }, 1500); ``` 这样做可以确保toast框在loading框完全隐藏后一段时间内显示,避免了toast框闪烁消失的问题。综上所述,通过调整代码的执行顺序或加入适当的延迟,可以解决uni.showToast真机一闪而过的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值