微信小程序之wx.hideLoading()无效和wx.navigateBack传递json(对象)数据

1、无效代码:

if (wx.showLoading) {
      wx.showToast({
        icon: 'loading',
        title: 'Loading',
        mask: true
      })
    };
wx.showLoading({ mask: true, title: '加载中...' })

异步获取数据后

wx.hideLoading();

测试结果
在微信开发者工具和iOS上都能正常隐藏loading框,安卓手机上无法隐藏。

2、解决办法:

   (1):设置定时


setTimeout(() => {
    wx.hideLoading();
    wx.showToast({
    icon: 'loading',
    title: 'Loading',
    mask: true
   })
}, 100); 

(2):检查是否与wx.navigateBack({ })连用,如果联合使用则去掉一个

3、wx.navigateBack({ })相关error:

      (1):wx.showToast尽量不要与其连用(放在一块儿使用)会造成遮罩(Android机);

      (2):wx.showModal与其连用

 wx.showModal({
	 title: '提示',
	 content:res.msg,
	 success: function(res) {
		    	wx.navigateBack();
		    }
});

4、wx.navigateBack传递json对象:

    (1):传递json数据(对象)

//e为页面选择的数据
函数名:function(e){
    var page = this;
    var item = e.currentTarget.dataset.index;
    if (item != null){
      wx.navigateTo({
        url: '/pages/xxx/xxx?item=' + JSON.stringify(item),
      })
    }else{
      wx.showToast({
        title: "文件出错!",
        image: "/images/img/icon-warning.png"
      });
    }
  }

   (2):解析json数据(页面接收参数 解析json)

//pages/xxx/xxx接收参数
onLoad: function (options) {
    var page = this;
    var item = JSON.parse(options.item);
},

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我无法提供完整的微信小程序50个api和组件用法及案例代码。但是,我可以给你提供一些常用的微信小程序api和组件及其简单用法: 1. wx.request() - 发起网络请求 ``` wx.request({ url: 'url', data: {}, header: {}, method: 'GET/POST/PUT/DELETE', dataType: 'json', responseType: 'text', success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) ``` 2. wx.navigateTo() - 跳转到页面 ``` wx.navigateTo({ url: 'url' }) ``` 3. wx.showLoading() - 显示加载提示框 ``` wx.showLoading({ title: 'loading', mask: true, }) ``` 4. wx.hideLoading() - 隐藏加载提示框 ``` wx.hideLoading() ``` 5. wx.showToast() - 显示消息提示框 ``` wx.showToast({ title: 'message', icon: 'success/warning/none', duration: 2000, }) ``` 6. wx.showModal() - 显示模态框 ``` wx.showModal({ title: 'title', content: 'content', showCancel: true, cancelText: 'cancel', confirmText: 'confirm', success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) ``` 7. wx.getStorageSync() - 同步获取本地数据缓存 ``` wx.getStorageSync('key') ``` 8. wx.setStorageSync() - 同步设置本地数据缓存 ``` wx.setStorageSync('key', 'value') ``` 9. wx.createAnimation() - 创建动画实例 ``` var animation = wx.createAnimation({ duration: 1000, timingFunction: 'ease', delay: 0, transformOrigin: '50% 50% 0', }) ``` 10. wx.createCanvasContext() - 创建画布上下文 ``` var context = wx.createCanvasContext('canvas') ``` 以上是一些常用的微信小程序api和组件及其简单用法,希望对你有所帮助。如果需要更详细的内容和案例代码,建议你去官方文档查阅。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值