商城系統(tǒng) 注冊(cè)

微信小程序api有哪些,微信小程序api列表及使用說(shuō)明

2018-05-28|HiShop
導(dǎo)讀:框架提供豐富的微信原生API,可以方便的調(diào)起微信提供的能力,如獲取用戶(hù)信息,本地存儲(chǔ),支付功能等。...

微信小程序api有哪些,微信小程序api列表及使用說(shuō)明

  API

  框架提供豐富的微信原生API,可以方便的調(diào)起微信提供的能力,如獲取用戶(hù)信息,本地存儲(chǔ),支付功能等。

  說(shuō)明:

  wx.on 開(kāi)頭的 API 是監(jiān)聽(tīng)某個(gè)事件發(fā)生的API接口,接受一個(gè) CALLBACK 函數(shù)作為參數(shù)。當(dāng)該事件觸發(fā)時(shí),會(huì)調(diào)用 CALLBACK 函數(shù)。

  如未特殊約定,其他 API 接口都接受一個(gè)OBJECT作為參數(shù)。

  OBJECT中可以指定success, fail, complete來(lái)接收接口調(diào)用結(jié)果。

  參數(shù)名類(lèi)型必填說(shuō)明

  successFunction否接口調(diào)用成功的回調(diào)函數(shù)

  failFunction否接口調(diào)用失敗的回調(diào)函數(shù)

  completeFunction否接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會(huì)執(zhí)行)

  API列表:

  網(wǎng)絡(luò) API 列表:

  API說(shuō)明

  wx.request發(fā)起網(wǎng)絡(luò)請(qǐng)求

  wx.uploadFile上傳文件

  wx.downloadFile下載文件

  wx.connectSocket創(chuàng)建 WebSocket 連接

  wx.onSocketOpen監(jiān)聽(tīng) WebSocket 打開(kāi)

  wx.onSocketError監(jiān)聽(tīng) WebSocket 錯(cuò)誤

  wx.sendSocketMessage發(fā)送 WebSocket 消息

  wx.onSocketMessage接受 WebSocket 消息

  wx.closeSocket關(guān)閉 WebSocket 連接

  wx.onSocketClose監(jiān)聽(tīng) WebSocket 關(guān)閉

  媒體 API 列表:

  API說(shuō)明

  wx.chooseImage從相冊(cè)選擇圖片,或者拍照

  wx.previewImage預(yù)覽圖片

  wx.startRecord開(kāi)始錄音

  wx.stopRecord結(jié)束錄音

  wx.playVoice播放語(yǔ)音

  wx.pauseVoice暫停播放語(yǔ)音

  wx.stopVoice結(jié)束播放語(yǔ)音

  wx.getBackgroundAudioPlayerState獲取音樂(lè)播放狀態(tài)

  wx.playBackgroundAudio播放音樂(lè)

  wx.pauseBackgroundAudio暫停播放音樂(lè)

  wx.seekBackgroundAudio控制音樂(lè)播放進(jìn)度

  wx.stopBackgroundAudio停止播放音樂(lè)

  wx.onBackgroundAudioPlay監(jiān)聽(tīng)音樂(lè)開(kāi)始播放

  wx.onBackgroundAudioPause監(jiān)聽(tīng)音樂(lè)暫停

  wx.onBackgroundAudioStop監(jiān)聽(tīng)音樂(lè)結(jié)束

  wx.chooseVideo從相冊(cè)選擇視頻,或者拍攝

  文件 API 列表:

  API說(shuō)明

  wx.saveFile保存文件

  wx.getSavedFileList獲取已保存的文件列表

  wx.getSavedFileInfo獲取已保存的文件信息

  wx.removeSavedFile刪除已保存的文件信息

  wx.openDocument打開(kāi)文件

  數(shù)據(jù) API 列表:

  API說(shuō)明

  wx.getStorage獲取本地?cái)?shù)據(jù)緩存

  wx.getStorageSync獲取本地?cái)?shù)據(jù)緩存

  wx.setStorage設(shè)置本地?cái)?shù)據(jù)緩存

  wx.setStorageSync設(shè)置本地?cái)?shù)據(jù)緩存

  wx.getStorageInfo獲取本地緩存的相關(guān)信息

  wx.getStorageInfoSync獲取本地緩存的相關(guān)信息

  wx.removeStorage刪除本地緩存內(nèi)容

  wx.removeStorageSync刪除本地緩存內(nèi)容

  wx.clearStorage清理本地?cái)?shù)據(jù)緩存

  wx.clearStorageSync清理本地?cái)?shù)據(jù)緩存

  位置 API 列表:

  API說(shuō)明

  wx.getLocation獲取當(dāng)前位置

  wx.chooseLocation打開(kāi)地圖選擇位置

  wx.openLocation打開(kāi)內(nèi)置地圖

  wx.createMapContext地圖組件控制

  設(shè)備 API 列表:

  API說(shuō)明

  wx.getNetworkType獲取網(wǎng)絡(luò)類(lèi)型

  wx.onNetworkStatusChange監(jiān)聽(tīng)網(wǎng)絡(luò)狀態(tài)變化

  wx.getSystemInfo獲取系統(tǒng)信息

  wx.getSystemInfoSync獲取系統(tǒng)信息

  wx.onAccelerometerChange監(jiān)聽(tīng)加速度數(shù)據(jù)

  wx.startAccelerometer開(kāi)始監(jiān)聽(tīng)加速度數(shù)據(jù)

  wx.stopAccelerometer停止監(jiān)聽(tīng)加速度數(shù)據(jù)

  wx.onCompassChange監(jiān)聽(tīng)羅盤(pán)數(shù)據(jù)

  wx.startCompass開(kāi)始監(jiān)聽(tīng)羅盤(pán)數(shù)據(jù)

  wx.stopCompass停止監(jiān)聽(tīng)羅盤(pán)數(shù)據(jù)

  wx.setClipboardData設(shè)置剪貼板內(nèi)容

  wx.getClipboardData獲取剪貼板內(nèi)容

  wx.makePhoneCall撥打電話(huà)

  wx.scanCode掃碼

  界面 API 列表:

  API說(shuō)明

  wx.showToast顯示提示框

  wx.showLoading顯示加載提示框

  wx.hideToast隱藏提示框

  wx.hideLoading隱藏提示框

  wx.showModal顯示模態(tài)彈窗

  wx.showActionSheet顯示菜單列表

  wx.setNavigationBarTitle設(shè)置當(dāng)前頁(yè)面標(biāo)題

  wx.showNavigationBarLoading顯示導(dǎo)航條加載動(dòng)畫(huà)

  wx.hideNavigationBarLoading隱藏導(dǎo)航條加載動(dòng)畫(huà)

  wx.navigateTo新窗口打開(kāi)頁(yè)面

  wx.redirectTo原窗口打開(kāi)頁(yè)面

  wx.switchTab切換到 tabbar 頁(yè)面

  wx.navigateBack退回上一個(gè)頁(yè)面

  wx.createAnimation動(dòng)畫(huà)

  wx.createContext創(chuàng)建繪圖上下文

  wx.drawCanvas繪圖

  wx.stopPullDownRefresh停止下拉刷新動(dòng)畫(huà)

  WXML節(jié)點(diǎn)信息 API 列表:

  API說(shuō)明

  wx.createSelectorQuery創(chuàng)建查詢(xún)請(qǐng)求

  selectorQuery.in指定在哪個(gè)自定義組件中選取節(jié)點(diǎn)

  selectorQuery.select根據(jù)選擇器選擇單個(gè)節(jié)點(diǎn)

  selectorQuery.selectAll根據(jù)選擇器選擇全部節(jié)點(diǎn)

  selectorQuery.selectViewport選擇顯示區(qū)域

  nodesRef.boundingClientRect獲取布局位置和尺寸

  nodesRef.scrollOffset獲取滾動(dòng)位置

  nodesRef.fields獲取任意字段

  selectorQuery.exec執(zhí)行查詢(xún)請(qǐng)求

  WXML節(jié)點(diǎn)布局相交狀態(tài):

  API說(shuō)明

  wx.createIntersectionObserver創(chuàng)建 IntersectionObserver 對(duì)象

  intersectionObserver.relativeTo指定參照節(jié)點(diǎn)

  intersectionObserver.relativeToViewport指定頁(yè)面顯示區(qū)域作為參照區(qū)域

  intersectionObserver.observe指定目標(biāo)節(jié)點(diǎn)并開(kāi)始監(jiān)聽(tīng)

  intersectionObserver.disconnect停止監(jiān)聽(tīng)

  開(kāi)放接口:

  API說(shuō)明

  wx.login登錄

  wx.getUserInfo獲取用戶(hù)信息

  wx.chooseAddress獲取用戶(hù)收貨地址

  wx.requestPayment發(fā)起微信支付

  wx.addCard添加卡券

  wx.openCard打開(kāi)卡券

電話(huà)咨詢(xún) 預(yù)約演示 0元開(kāi)店