What are the three categories of WeChat Mini Program API? How to distinguish?

Mini Programs officially divide APIs into three categories:

1. Event monitoring API

2. Synchronous APIs

3. Asynchronous APIs

How to distinguish the characteristics of these three APIs? Let me talk about it next.

1. Event monitoring API

        Features: start with on , used to monitor the triggering of certain events

        Example: wx.onWindowResize (function callback) monitors the event of window size change

The following pictures are all event monitoring apis starting with on

 2. Synchronous APIs

        Feature 1: APIs ending with Sync are all synchronous APIs

        Feature 2: The execution result of the synchronous API can be obtained directly through the return value of the function. If an error occurs directly, an exception will be thrown

        Example: wx.setStoraheSync('key', 'value') writes content to local storage

The following pictures are all synchronous APIs at the end of Sync

 3. Asynchronous APIs

        Features: Similar to the $.ajax(options) function in jQuery, it needs to receive the result of the call through success, fail, and complete

        Example: wxrequest() initiates a network data request and receives data through the success callback function

Similar to the picture below

 

The above are the detailed characteristics of the API divided into three categories.

Guess you like

Origin blog.csdn.net/weixin_50123771/article/details/128909611