Home > Article > WeChat Applet > Solution to disconnection and reloading during WeChat development
微信小程序目前没有提供刷新API,所以要自己去记录当前操作,点击刷新重新执行一遍
##Click 'Reload' to reload the pageImplementationSince when working on a project, page rendering is inseparable from
/** * obj request请求参数 * cb requrst请求成功回掉 * page 当前page实例 **/ function wxRequest (obj, cb, page, type) { var isOne = true var cachFn = function () { wx.request({ url: obj.url, data: obj.data || {}, method: obj.method || 'GET', success: function (res) { cb.call(page, res) if (!page.data.isNet) { page.setData({ isNet: true }) } }, // fail执行时当断网处理 fail: function () { // 防止fail 有时会执行两次,影响渲染 if (!isOne) { return } page.setData({ isNet: false, isRequested: false }) // 记录本次请求,加载时,执行page实例的reloadFn即可 page.reloadFn = wxRequest(obj, cb, page, 1) isOne = false } }) } if (type) { page.isRequested = true } return type ? cachFn : cachFn() }Application
let data = { url: '', data: {}, method: '' } wxTools.wxRequest(data, (res) => { // 数据渲染 this.setData({}) }, this)
1.
Complete source code of WeChat Mini Program
2.WeChat Mini Program demo: Yangtao
The above is the detailed content of Solution to disconnection and reloading during WeChat development. For more information, please follow other related articles on the PHP Chinese website!