


Commonly used APIs for WeChat mini programs (summary sharing)
Dec 01, 2022 pm 04:08 PM本篇文章給大家?guī)砹岁P(guān)于微信小程序的相關(guān)知識,其中主要總結(jié)了一些常用的API,下面一起來看一下,希望對大家有幫助。
【相關(guān)學(xué)習(xí)推薦:小程序?qū)W習(xí)教程】
一、 系統(tǒng)常用api
1. wx.openAppAuthorizeSetting(Object object) 跳轉(zhuǎn)系統(tǒng)微信授權(quán)管理頁
參數(shù) 1)success??接口調(diào)用成功的回調(diào)函數(shù) 2)fail??接口調(diào)用失敗的回調(diào)函數(shù) 3)complete??接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)
2. wx.getWindowInfo() 獲取窗口信息
參數(shù) 1)pixelRatio 設(shè)備像素比 2)screenWidth 屏幕寬度,單位px 3)screenHeight 屏幕高度,單位px 4)windowWidth 可使用窗口寬度,單位px 5)windowHeight?可使用窗口高度,單位px 6)statusBarHeight 狀態(tài)欄的高度,單位px 7)safeArea 在豎屏正方向下的安全區(qū)域 left 安全區(qū)域左上角橫坐標(biāo) right 安全區(qū)域右下角橫坐標(biāo) top 安全區(qū)域左上角縱坐標(biāo) bottom 安全區(qū)域右下角縱坐標(biāo) width 安全區(qū)域的寬度,單位邏輯像素 height 安全區(qū)域的高度,單位邏輯像素 8)screenTop 窗口上邊緣的?y?值.
3. wx.getSystemInfoAsync(Object object) 異步獲取系統(tǒng)信息。需要一定的微信客戶端版本支持,在不支持的客戶端上,會使用同步實現(xiàn)來返回。
參數(shù) 1)success??接口調(diào)用成功的回調(diào)函數(shù) 2)fail??接口調(diào)用失敗的回調(diào)函數(shù) 3)complete??接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、 失敗都會執(zhí)行)
4. wx.getAppAuthorizeSetting() 獲取微信 APP 授權(quán)設(shè)置
albumAuthorized 允許微信使用相冊的開關(guān)(僅?iOS?有效) bluetoothAuthorized 允許微信使用藍牙的開關(guān)(僅?iOS?有效) cameraAuthorized?允許微信使用攝像頭的開關(guān) locationAuthorized 允許微信使用定位的開關(guān) locationReducedAccuracy 定位準(zhǔn)確度。true?表示模糊定位,false?表示精確定位(僅?iOS?有效) microphoneAuthorized?允許微信使用麥克風(fēng)的開關(guān) notificationAuthorized?允許微信通知的開關(guān) notificationAlertAuthorized 允許微信通知帶有提醒的開關(guān)(僅?iOS?有效) notificationBadgeAuthorized 允許微信通知帶有標(biāo)記的開關(guān)(僅?iOS?有效) notificationSoundAuthorized 允許微信通知帶有聲音的開關(guān)(僅?iOS?有效) phoneCalendarAuthorized 允許微信讀寫日歷的開關(guān)
二、小程序常用api
小程序常用生命周期
wx.getLaunchOptionsSync 獲取小程序啟動時的參數(shù)。與 App.onLaunch 的回調(diào)參數(shù)一致。
wx.getEnterOptionsSync 獲取本次小程序啟動時的參數(shù)。如果當(dāng)前是冷啟動,則返回值與 App.onLaunch 的回調(diào)參數(shù)一致;如果當(dāng)前是熱啟動,則返回值與 App.onShow 一致。
wx.onUnhandledRejection(function listener) 監(jiān)聽未處理的 Promise 拒絕事件。該事件與 App.onUnhandledRejection 的回調(diào)時機與參數(shù)一致。
wx.onThemeChange(function listener) 監(jiān)聽系統(tǒng)主題改變事件。該事件與 App.onThemeChange 的回調(diào)時機一致。
wx.onPageNotFound(function listener) 監(jiān)聽小程序要打開的頁面不存在事件。該事件與 App.onPageNotFound 的回調(diào)時機一致。
wx.onLazyLoadError(function listener) 監(jiān)聽小程序異步組件加載失敗事件。
wx.onError(function listener) 監(jiān)聽小程序錯誤事件。如腳本錯誤或 API 調(diào)用報錯等。該事件與 App.onError 的回調(diào)時機與參數(shù)一致。
wx.onAudioInterruptionEnd(function listener) 監(jiān)聽音頻中斷結(jié)束事件。在收到 onAudioInterruptionBegin 事件之后,小程序內(nèi)所有音頻會暫停,收到此事件之后才可再次播放成功
wx.onAppShow(function listener) 監(jiān)聽小程序切前臺事件。該事件與 App.onShow 的回調(diào)參數(shù)一致。
wx.onAppHide(function listener) 監(jiān)聽小程序切后臺事件。該事件與 App.onHide 的回調(diào)時機一致。
三、路由跳轉(zhuǎn)api
wx.switchTab(Object object) 跳轉(zhuǎn)到 tabBar 頁面,并關(guān)閉其他所有非 tabBar 頁面
wx.reLaunch(Object object) 關(guān)閉所有頁面,打開到應(yīng)用內(nèi)的某個頁面
wx.redirectTo(Object object) 關(guān)閉當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個頁面。但是不允許跳轉(zhuǎn)到 tabbar 頁面。
wx.navigateTo(Object object) 保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個頁面。但是不能跳到 tabbar 頁面。使用 wx.navigateBack 可以返回到原頁面。小程序中頁面棧最多十層。
wx.navigateBack(Object object) 關(guān)閉當(dāng)前頁面,返回上一頁面或多級頁面??赏ㄟ^ getCurrentPages 獲取當(dāng)前的頁面棧,決定需要返回幾層。
wx.exitMiniProgram(Object object) 退出當(dāng)前小程序。必須有點擊行為才能調(diào)用成功。
四、轉(zhuǎn)發(fā)api
wx.updateShareMenu(Object object) 更新轉(zhuǎn)發(fā)屬性
wx.showShareMenu(Object object) 顯示當(dāng)前頁面的轉(zhuǎn)發(fā)按鈕
wx.showShareImageMenu(Object object) 打開分享圖片彈窗,可以將圖片發(fā)送給朋友、收藏或下載
wx.shareVideoMessage(Object object) 轉(zhuǎn)發(fā)視頻到聊天
wx.shareFileMessage(Object object) 轉(zhuǎn)發(fā)文件到聊天
五、頁面交互
wx.showToast(Object object) 顯示消息提示框
wx.showModal(Object object) 顯示模態(tài)對話框
wx.showLoading(Object object) 顯示 loading 提示框。需主動調(diào)用 wx.hideLoading 才能關(guān)閉提示框
wx.showActionSheet(Object object) 顯示操作菜單
wx.hideToast(Object object) 隱藏消息提示框
wx.hideLoading(Object object) 隱藏 loading 提示框
wx.enableAlertBeforeUnload(Object object) 開啟小程序頁面返回詢問對話框。
wx.disableAlertBeforeUnload(Object object) Close the mini program page and return to the query dialog box.
[Related learning recommendations: 小program learning tutorial]
The above is the detailed content of Commonly used APIs for WeChat mini programs (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Xianyu's official WeChat mini program has quietly been launched. In the mini program, you can post private messages to communicate with buyers/sellers, view personal information and orders, search for items, etc. If you are curious about what the Xianyu WeChat mini program is called, take a look now. What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3. If you want to use it, you must activate WeChat payment before you can purchase it;

Implementing picture filter effects in WeChat mini programs With the popularity of social media applications, people are increasingly fond of applying filter effects to photos to enhance the artistic effect and attractiveness of the photos. Picture filter effects can also be implemented in WeChat mini programs, providing users with more interesting and creative photo editing functions. This article will introduce how to implement image filter effects in WeChat mini programs and provide specific code examples. First, we need to use the canvas component in the WeChat applet to load and edit images. The canvas component can be used on the page

To implement the drop-down menu effect in WeChat Mini Programs, specific code examples are required. With the popularity of mobile Internet, WeChat Mini Programs have become an important part of Internet development, and more and more people have begun to pay attention to and use WeChat Mini Programs. The development of WeChat mini programs is simpler and faster than traditional APP development, but it also requires mastering certain development skills. In the development of WeChat mini programs, drop-down menus are a common UI component, achieving a better user experience. This article will introduce in detail how to implement the drop-down menu effect in the WeChat applet and provide practical

The official WeChat mini program of Xianyu has been quietly launched. It provides users with a convenient platform that allows you to easily publish and trade idle items. In the mini program, you can communicate with buyers or sellers via private messages, view personal information and orders, and search for the items you want. So what exactly is Xianyu called in the WeChat mini program? This tutorial guide will introduce it to you in detail. Users who want to know, please follow this article and continue reading! What is the name of the Xianyu WeChat applet? Answer: Xianyu, idle transactions, second-hand sales, valuations and recycling. 1. In the mini program, you can post idle messages, communicate with buyers/sellers via private messages, view personal information and orders, search for specified items, etc.; 2. On the mini program page, there are homepage, nearby, post idle, messages, and mine. 5 functions; 3.

WeChat applet implements picture upload function With the development of mobile Internet, WeChat applet has become an indispensable part of people's lives. WeChat mini programs not only provide a wealth of application scenarios, but also support developer-defined functions, including image upload functions. This article will introduce how to implement the image upload function in the WeChat applet and provide specific code examples. 1. Preparatory work Before starting to write code, we need to download and install the WeChat developer tools and register as a WeChat developer. At the same time, you also need to understand WeChat

Use the WeChat applet to achieve the carousel switching effect. The WeChat applet is a lightweight application that is simple and efficient to develop and use. In WeChat mini programs, it is a common requirement to achieve carousel switching effects. This article will introduce how to use the WeChat applet to achieve the carousel switching effect, and give specific code examples. First, add a carousel component to the page file of the WeChat applet. For example, you can use the <swiper> tag to achieve the switching effect of the carousel. In this component, you can pass b

To implement the picture rotation effect in WeChat Mini Program, specific code examples are required. WeChat Mini Program is a lightweight application that provides users with rich functions and a good user experience. In mini programs, developers can use various components and APIs to achieve various effects. Among them, the picture rotation effect is a common animation effect that can add interest and visual effects to the mini program. To achieve image rotation effects in WeChat mini programs, you need to use the animation API provided by the mini program. The following is a specific code example that shows how to

Implementing the sliding delete function in WeChat mini programs requires specific code examples. With the popularity of WeChat mini programs, developers often encounter problems in implementing some common functions during the development process. Among them, the sliding delete function is a common and commonly used functional requirement. This article will introduce in detail how to implement the sliding delete function in the WeChat applet and give specific code examples. 1. Requirements analysis In the WeChat mini program, the implementation of the sliding deletion function involves the following points: List display: To display a list that can be slid and deleted, each list item needs to include
