当前位置:网站首页>[wechat applet] Chapter (5): basic API interface of wechat applet

[wechat applet] Chapter (5): basic API interface of wechat applet

2022-07-07 15:46:00 wangzirui32

Bowen author wangzirui32
Like can give the thumbs-up Collection Pay attention to ~~
This article was first published in CSDN, Reprint is prohibited without permission


hello, Hello everyone , I am a wangzirui32, Today, let's learn the basics of wechat applet API Interface , Start learning !

1. wx.request

function : Request data from the server , Only initiation is supported HTTPS Network request .
Parameters :
 Parameters
Example :

   wx.request({
    
      url: 'https://114.51.4.191',
      data: {
    
        "a": "abc"
      },
    })

2. wx.downloadFile

function : Download files on the network .
attribute :
 attribute
Callback function parameters after successful request :
 Parameters
Example :

    wx.downloadFile({
    
      url: 'https://11.45.14.19/files/19810',  //  Example resource address 
      success (res) {
    
        if (res.statusCode === 200) {
    
          alert("OK");
        };
    }})

3.wx.uploadFile()

function : Upload the file to the designated url.
attribute
 attribute
Call successfully callback parameters :
 Parameters
Example :

wx.uploadFile({
    
      url: 'https://11.45.14.19/upload',
      filePath: "example_filepath",
      name: 'file',
      formData: {
    
        'date': '2022-7-5'
      },
      success (res){
    
        var data = res.data;
      }
    })

4. wx.switchTab

function : Jump to TabBar page .
attribute :
 attribute
Example :

    wx.switchTab({
    
      url: '/example_1'
    })

5. wx.reLaunch

function : Close all pages , Open to a page in the app .
attribute :
 attribute
Example :

    wx.reLaunch({
    
      url: '/example_2'
    })

6. wx.redirectTo

function : Jump to a page .
attribute :
 attribute
Example :

    wx.redirectTo({
    
      url: '/example_3'
    })

7. wx.navigateTo

function : Keep the current page , Jump to a page in the app .
attribute :
 attribute
Example :

    wx.navigateTo({
    
      url: '/example_4'
    })

8. wx.navigateBack

function : Close current page , Go back to the previous page .
attribute :
 attribute
Example :

    wx.navigateBack({
    
      url: '/example_5'
    })

9. EventChannel

9.1 EventChannel.emit

function : Trigger an event .
structure :

EventChannel.emit( Event name )

9.2 EventChannel.off

function : Cancel listening for an event .
structure :

EventChannel.off( Event name ,  Callback function )

9.3 EventChannel.on

function : Keep listening for an event .
structure :

EventChannel.on( Event name ,  Callback function )

9.4 EventChannel.once

function : Listen to an event once , Failure after triggering .
structure :

EventChannel.once( Event name ,  Callback function )

10. wx.canIUse

function : Judge the... Of the applet API, Callback , Parameters , Is the component available in the current version .
Return value : Boolean value (True perhaps False).
structure :

wx.canIUse(schema)
// schema  Parameter format ( Yes 2 Kind of )
// 1. ${API}.${method}.${param}.${option}
// 2. ${component}.${attribute}.${option}

Okay , That's all for today's lesson , I am a wangzirui32, You can collect and pay attention to what you like , See you next time !

原网站

版权声明
本文为[wangzirui32]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071326163664.html