Small program study notes (3) components

Components

In the applet, you only need to  WXML write the corresponding component label name to display the component on the interface, such as: display the map on the interface:

<map></map>

When using components, you can also pass values ​​to the components through attributes, so that the components can be displayed in different states. For example, if we want the center of the map to begin with the latitude and longitude of Guangzhou, then you need to declare the map's longitude (center longitude) and Two attributes of latitude:

<map longitude="广州经度" latitude="广州纬度"></map>

<map bindmarkertap="markertap" longitude="广州经度" latitude="广州纬度"></map>

The markertap function is triggered when the user clicks a marker on the map  .

API

In order to allow developers to easily call up the capabilities provided by WeChat, such as obtaining user information, WeChat payment, etc., the applet provides many APIs for developers to use.

To get the user's geographic location, you only need to:

wx.getLocation({
  type: 'wgs84', success: (res) => { var latitude = res.latitude // 纬度 var longitude = res.longitude // 经度 } }) 

To call the WeChat sweep ability, only need:

wx.scanCode({
  success: (res) => { console.log(res) } })

需要注意的是:多数 API 的回调都是异步,你需要处理好代码逻辑的异步问题。

Guess you like

Origin www.cnblogs.com/Dasate/p/12699018.html