- To minimize unnecessary HTTPS requests, you can use the getStorageSync() and setStorageSync() methods to store data locally
- Avoid passing variables that are not bound to WXML into setData: setData operations cause the framework to handle some of the work associated with rendering the interface. An unbound variable is meant to be irrelevant to rendering the interface, and passing setData can cause unnecessary performance costs. If the data needs to be shared on the current page, you can define global variables (such as this.).
- Avoid passing a lot of new data every time setData: it will slow js compilation, for example, changing an item in an array of data, while setData can change only one item. When the amount of list data is too large, the method of step rendering loading can also be adopted.
/** * Add list data by step * @param {*} Lists list data * @param {*} Name Field name in data * @param {*} step Number of fields in each step * @param {*} interval Interval */ stepPushList({ lists, name, step = 10, interval = 300, reset = false }) { this._clearBaseStepPushTimer(); if (! lists || ! name || ! Array.isArray(lists)) return; if (lists.length <= 0) return; // The number of steps cannot be less than or equal to zero step = step <= 0? 10 : step; // If reset reset && (this.data[name] = []); let oldLists = this.data[name] || []; let newLists = this.copyData(lists); let pushLists = newLists.splice(0, step); SetListPartData ({partLists: pushLists, start: oldLists. Length, name, callback: () => { if (newLists.length <= 0) return; this._baseStepPushTimer = setTimeout(() => { this.stepPushList({ lists: newLists, name, step, interval }); }, interval || 300) } }); }, // Clear the step timer _clearBaseStepPushTimer() {this._basesteppushtimer && clearTimeout(this._basesteppushtimer); this._baseStepPushTimer = null; },Copy the code
- Not frequently called setData (or even inside a function call two setData function) : slide will feel caton, operation feedback delay is serious, because JS thread has been compiled to perform rendering, fail to transfer the user action event to the logical layer, logic layer could not handled in a timely manner will result in a timely manner to the view layer.
- Avoid using the active pseudo-class for clickability. Use the ‘hover-class’ property of the applet built-in component instead.
- Avoid using: Obtaining the deep properties of the object may cause wechat alarms, so you can use the default value of the object structure to increase the code rigor, otherwise the applet assistant will report an alarm error.
- Avoid page nodes nested too deeply, increase the page rendering pressure
- Destroying the timer before the page exits can be done in the onUnLoad lifecycle hook function