如何让 uni.showToast() 的领取成功提示字体更大更清晰?

在使用 uni.showToast() 显示领取成功提示时,有时需要将字体大小设置得更大,以便用户更清楚地看到提示内容。以下方法可以实现:

方法:使用 uni.showToast() 的 complete 回调函数

  1. 添加 complete 回调函数

在 uni.showToast() 的调用中添加一个 complete 回调函数,该回调函数会在 toast 隐藏后执行。

uni.showToast({
    title: '领取成功:' + res.data.money + '元',
    icon: 'none',
    complete: () => {
        // 在这里设置字体大小
    }
})
  1. 在 complete 回调函数中使用 setTimeout 延时隐藏 toast

在 complete 回调函数中使用 setTimeout 函数来延时隐藏 toast,这将使 toast 显示的时间更长,让用户有更多时间看到提示内容。

uni.showToast({
    title: '领取成功:' + res.data.money + '元',
    icon: 'none',
    complete: () => {
        setTimeout(() => {
            uni.hideToast();
        }, 2000); // 设置延时时间为 2 秒
    }
})

完整代码示例:

// 手机号弹窗的确认按钮
Confirm() {
    if (!this.othersPhone) {
        this.common.UshowToast('请输入手机号');
    } else {
        let param = {
            openId: this.openId,
            storeId: this.info.storeId,
            phone: this.othersPhone,
            wxOrZfb: this.wxOrZfb
        }
        this.ajax.post(this.jk.addUser, param).then(res => {
            this.showw = false;
            this.$refs.popupOther.close();
            if (res.status == 200) {
                uni.showToast({
                    title: '领取成功:' + res.data.money + '元',
                    icon: 'none',
                    complete: () => {
                        setTimeout(() => {
                            uni.hideToast();
                        }, 2000); // 设置延时时间为 2 秒
                    }
                })
                this.user = res.data.user;
            }
        })
    }
},

通过以上方法,您可以轻松地将 uni.showToast() 的领取成功提示字体设置得更大,并使用 setTimeout 函数来延时隐藏 toast,使提示信息更加清晰易读。

uni.showToast() 如何设置字体大小 - 领取成功提示更清晰

原文地址: http://www.cveoy.top/t/topic/gPr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录