How to avoid n times start of onShow event in app.js in wechat small program
During development, there was a small problem that the onShow event in app.js would be triggered by calling other apis, such as wx.ChooseImage, wx.MakePhonecall, wx.previewImage.
Hot launch of small programs is indeed a pit, because by scanning or sharing entry will also be hot launch, generally developers only in onLaunch to deal with the relevant logic of scanning entry, hot launch bug.
At present, a better way is to judge the scene entered by the first parameter option in onShow and process the relevant logic according to the scene.
In the forwarding scenario, you can put the business code in the onLoad function, because the shared event will not execute onLoad, only onShow.
A brief description of the micro channel small program related file types
- WXML: IS a set of tag language designed by the framework, combined with the basic components, event system, can build the structure of the page.
- WXSS: IS a style language for describing WXML component styles.
- Js: Handle logic, network requests.
- Json: Small program Settings, such as page registration, page title, and tarBar.
How do you encapsulate the data request of wechat applets
- Put all interfaces in js files and export them
- Create a method in app.js that encapsulates the request data
- Call encapsulated methods in child pages to request data
What parameters are passed the value of the method
- Add a data attribute to the HTML element to pass in the value we need, which is then retrieved by the param parameter of e.currenttarget. dataset or onload. However, the data name cannot have uppercase letters and cannot store objects.
- Get the value of the set ID through e.currenttarget. id, and then pass the value by setting the global object.
- Add parameter pass values in the Navigator.
What methods have you used to improve the application speed of wechat mini program
- Improve page loading speed
- User behavior prediction
- Reduce the size of the default data
- Componentization scheme
How to solve the small program asynchronous request problem
Call the function of the next component in the callback function
app.js
success:function(info){
that.apitnCallback(info)
}
Copy the code
index.js
onLoad:function(){
app.apitnCallback = res= >{
console.log(res)
}
}
Copy the code
How is bidirectional binding of applets different from vUE
This. Data attributes cannot be synchronized to the view directly from the applet.
this.setData({noBind:true})
Copy the code
How to implement the pull down refresh
First configure enablePullDownRefresh on window in global Config
The onPullDownRefresh hook function is defined in the Page. When the pulldownRefresh condition is reached, the hook function executes, initiates the request method, and when the request returns, calls wx.stopPullDownRefresh to stop the pulldownRefresh.
What is the difference between bindtap and catchtap
The same
First of all, they’re all called click event functions, which are triggered when you click. In this function they are the same, you can make no distinction.
The difference between
The main difference is that Bindtap does not prevent bubbling and Catchtap does prevent bubbling.
Wx.navigateto (), wx.redirectto (), wx.switchtab (), wx.Navigateback (), wx.relaunch (
- Wx.navigateto () : Leave the current page and jump to a page in the app. But you cannot jump to the Tabbar page.
- Wx.redirectto () : closes the current page to jump to a page in the application. But you cannot jump to the Tabbar page.
- Wx.switchtab () : Switches to the abBar page and closes all non-Tabbar pages.
- Wx.navigateback () : Close the current page and return to the previous page or multiple levels of the page. through
getCurrentPages()
Get the current page stack and decide how many layers to return to. - Wx.relaunch () : Close all pages and open to a page within the app.