当前位置: 首页 > news >正文

电商网站建设实训步骤无锡网络营销推广公司

电商网站建设实训步骤,无锡网络营销推广公司,模板展示网站源码,兰州网络推广昔年下拉博客uniapp踩坑 uni.showToast 和 uni.showLoading 一、问题描述 uni.showLoading 和 uni.showToast 混合使用时,showLoading和showToast会相互覆盖对方,调用hideLoading时也会将toast内容进行隐藏。 二、触发条件 1.uniapp中使用自己封装的axois&#x…

uniapp踩坑 uni.showToast 和 uni.showLoading

一、问题描述

  • uni.showLoading 和 uni.showToast 混合使用时,showLoading和showToast会相互覆盖对方,调用hideLoading时也会将toast内容进行隐藏。

二、触发条件

  • 1.uniapp中使用自己封装的axois,拦截器使用 uni.showToast 做异常信息处理
  • 2.业务中使用 uni.showLoading 做业务处理
  • 3.当请求异常被catch抓到,使用 uni.hideLoading 清除 loading 时,异常信息 toast 会被覆盖掉。

三、解决思路

  • 小程序将Toast和Loading放到同一层渲染引起的,而且缺乏一个优先级判断,也没有提供Toast、Loading是否正在显示的接口供业务侧判断。所以我们自己实现这套逻辑,判断其中有一个已经渲染,泽不执行另一个。

四、实现方案

1.封装一下toast和loading

/*** 显示消息提示框* @param title* @param options* @constructor*/
export function Toast(title: string, options?: Partial<UniApp.ShowToastOptions>) {uni.showToast({title,duration: 1500,icon: 'none',mask: true,...options,});
}/*** 隐藏消息提示框*/
export function HideToast() {uni.hideToast();
}/*** 显示 loading 提示框* @param title* @param options* @constructor*/
export function Loading(title: string, options?: Partial<UniApp.ShowLoadingOptions>) {uni.showLoading({title,mask: true,...options,});
}/*** 隐藏 loading 提示框*/
export function HideLoading() {uni.hideLoading();
}

2.要加个变量控制toast和loading的优先级,最简单就是通过vue的全局状态管理来控制

export const usePromptStore = defineStore({id: 'promptStore',state: (): IState => ({isShowLoading: false,isShowToast: false,}),getters: {getIsShowLoading: (state) => state.isShowLoading,getIsShowToast: (state) => state.isShowToast,},actions: {setIsShowLoading(val: boolean) {this.isShowLoading = val;},setIsShowToast(val: boolean) {this.isShowToast = val;},},
});

3.改造一下封装的toast和loading

/*** 显示消息提示框* @param title* @param options* @constructor*/
export function Toast(title: string, options?: Partial<UniApp.ShowToastOptions>) {const promptStore = usePromptStore();if (promptStore.disabledToast) return;if (promptStore.isShowLoading) {// Toast优先级更高HideLoading();}promptStore.setIsShowToast(true);uni.showToast({title,duration: 1500,icon: 'none',mask: true,...options,});const timer = setTimeout(() => {promptStore.setIsShowToast(false);clearTimeout(timer)}, 1500);
}/*** 隐藏消息提示框*/
export function HideToast() {const promptStore = usePromptStore();promptStore.setIsShowToast(false);uni.hideToast();
}/*** 显示 loading 提示框* @param title* @param options* @constructor*/
export function Loading(title: string, options?: Partial<UniApp.ShowLoadingOptions>) {const promptStore = usePromptStore();if (promptStore.isShowToast) {// Toast优先级更高return;}promptStore.setIsShowLoading(true);uni.showLoading({title,mask: true,...options,});
}/*** 隐藏 loading 提示框*/
export function HideLoading() {const promptStore = usePromptStore();if (promptStore.isShowToast) {// Toast优先级更高return;}promptStore.setIsShowLoading(false);uni.hideLoading();
}
http://www.yayakq.cn/news/895092/

相关文章:

  • 做网站的国标有哪些获胜者网站建设
  • 做网站页面对PS切图塘沽建设网站
  • 济南集团网站建设公司好社交网站怎么制作
  • 中山网站建设思建设股票网站
  • 花都商城网站建设wordpress press
  • 企业做国外网站多少钱美工网站做兼职
  • 武安城乡建设网站wordpress评论不能用
  • 网站建设飠金手指下拉附近的网站设计开发
  • 怎么做钓qq密码网站网站建设的公司选哪家
  • 网站建设招标书技术介绍中国纪检监察报邮箱
  • 企业网站建设好处网站关键词优化方案分为几个步骤
  • 2017优秀网站设计欣赏seo网站关键词排名软件
  • 网站不备案有什么后果网站首屏
  • 怎么是一个网站看起来高大上有哪些专业做饰品的网站app
  • 营销网站建设公司哪家好怎么做广告宣传最有效
  • 西安 餐饮 网站建设做淘宝客网站需要什么资质
  • 交互式网站备案难吗php医疗网站咨询源码
  • 聊城做网站的公司案例重庆建设工程信息官网
  • 苏州网站建设设计制作公司中国企业登记网
  • 河南建设厅特种工报考网站o2o商业模式
  • 网站建设框架文案高校二级网站建设意义
  • 高端网站设计高端网站制作网站的ftp在哪里可以查到
  • 网站搜索引擎莱芜有需要制作网站的公司吗
  • 推广网站优化seo教程上排名站内关键词自然排名优化
  • 制作网站要钱吗下载网站程序
  • 免费行情网站推荐百度惠生活商家怎么入驻
  • 兰州网站建设多少钱建立网站费用怎么做会计分录
  • 做网站论坛 前置许可美食网站建设项目规划书
  • 网站建设-信科网络vue适合做门户网站吗
  • 网站建设专员工作建设一个网站的流程.