Analyze {code ...} click "reload" to reload the page. as page rendering is inseparable from interface requests during Project creation, I encapsulated wx. request to determine whether the network is disconnected, and record this request after the network is disconnected {code ...} application {code ...} when the network is disconnected, execute this. re... analysis
The applet does not currently provide a refresh API. Therefore, you need to record the current operation and click refresh to execute it again.
Effect
Click "reload" to reload the page.
Implementation
As Page rendering is inseparable from interface requests during Project creation, I encapsulated wx. request to determine whether the network is disconnected and record this request after the network is disconnected.
/*** Obj request parameter * cb requrst request successfully returns * Current page instance */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}) }}, // when fail is executed, fail: function () {// prevents fail from being executed twice, affecting rendering if (! IsOne) {return} page. setData ({isNet: false, isRequested: false}) // record this request. when loading, execute reloadFn of the page instance to get the 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) =>{// data rendering this. setData ({})}, this)
When the network is disconnected, execute this. reloadFn to re-initiate the last request, isNet and determine whether the network is disconnected.