This is the fifth day of my participation in the August More text Challenge. For details, see: August More Text Challenge

Summarize some knowledge related to wechat small programs, organize notes to share with you, some knowledge will often be asked in front of the interview, so make a record, hope to help you, if there is any problem, you can point out, will actively correct. If you like, you can like or leave a message and I will continue to update the interview questions ~~~~, thank you ~~~

1. Briefly describe the related file types of wechat applet?

There are four main file types of the micro program project structure

  • WXML (WeiXin Markup Language) is a set of tag Language designed by the framework. Combined with basic components and event system, it can build the structure of the page. The internal is mainly a set of components defined by wechat itself
  • WXSS (WeiXin Style Sheets) is a set of Style languages for describing component styles of WXML
  • Js logic processing, network requests
  • Json applet Settings, such as page registration, page title and tabBar

The main file

  • App. json must have this file. Without this file, the project cannot run, because the wechat framework uses this as the entry to the configuration file, the global configuration of the whole applie. This includes page registration, network Settings, window background color for applets, navigation bar style, and default title configuration
  • App.js must have this file, or it will report an error! But this is a file that you just create and you don’t have to write anything and then you can listen in and handle the life cycle of small programs and declare global variables, right
  • App. WXSS optional

2. Where is the difference between the bidirectional binding of small programs and VUE?

The property of the applet directly to this.data cannot be synchronized to the view, and must be called:

this.setData({
    // Set here
})
Copy the code

3. What are the methods for transferring data between small program pages?

Define the global variable globalData in the app.js file and store the information that needs to be stored in it

// app.js
App({
     // Global variables
  globalData: {
    userInfo: null}})Copy the code

When using, use getApp() directly to get the stored information

With wX. navigateTo and wX.redirectto, you can put some data in the URL and initialize it when the new page is onLoad

// Navigate
wx.navigateTo({
  url: '.. /pageD/pageD? name=raymond&gender=male',})// Redirect
wx.redirectTo({
  url: '.. /pageD/pageD? name=raymond&gender=male',})// pageB.js. Page({onLoad: function(option){
    console.log(option.name + 'is' + option.gender)
    this.setData({
      option: option
    })
  }
})
Copy the code

Wx. navigateTo and wX. redirectTo do not allow jump to TAB contained pages onLoad only once using the local cache Storage related

4, small program life cycle function

  • OnLoad is triggered when the page is loaded. A page is called only once, and you can get the parameters in the onLoad parameter to open the current page path
  • OnShow () is triggered when the page is displayed/cut to the foreground
  • OnReady () is triggered when the first rendering of the page is complete. A page is called only once, indicating that the page is ready to interact with the view layer
  • OnHide () is triggered when the page hides/enters the background. Such as navigateTo or the bottom TAB to switch to other pages, small programs cut into the background
  • OnUnload () is triggered when the page is unloaded. Such as redirectTo or navigateBack to other pages

5, the advantages and disadvantages of wechat small program

advantage

  • That is, no installation, save traffic, save installation time, do not occupy the desktop
  • Relying on wechat traffic, natural promotion and communication advantages
  • Development cost is lower than App

disadvantages

  • Retention, when you go, is an advantage, but it also has some problems
  • The entrance is much deeper than the traditional App
  • The page size cannot exceed 2 MB. You cannot open pages with more than 10 levels

6,How to achieve the pulldown refresh

The onPullDownRefresh hook function is defined in the Page. After the pulldown refresh condition is reached, the hook function is executed. After the request is returned, Call wX. stopPullDownRefresh to stop the pulldown refresh

What is the difference between bindtap and catchtap?

Similarities: First, they both function as click events, which are triggered when clicked. Bindtap does not prevent bubbling events, but catchTap prevents bubbling

Wx.navigateto (), wX.redirectto (), wX.SwitchTab (), wX.navigateBack (), wX.relaunch ().

Wx.navigateto () : Keep the current page and jump to a page in the application. Wx.redirectto () : Close the current page and jump to a new page (similar to redirection). Wx. switchTab() : Switches to the Tabbar page and closes all other non-Tabbar pages. Wx. navigateBack(): closes the current page and returns to the previous page or multilevel page. You can get the current stack of pages from getCurrentPages() and determine how many layers you need to return to wX.relaunch () : close all pages and open to a page within the application

9,Login process?

The login process is to call wX. login to obtain the code and send it to the background server to obtain the unique OPENID of the wechat user and the session key (session_key) of the login. Wx.setstoragesync (‘sessionKey’, ‘value’)

Persistent login state: Session information is stored in a cookie and brought back to the server in the form of a request header in the wX. request header in request.js

10,Commonly used instructions

Wx: for, wx: the if

Other relevant summary articles

  • HTML Interview Summary
  • CSS Interview Summary
  • Summary of JS Interview
  • Summary of ES6 interview
  • Vue interview summary