tencent cloud

Tencent Cloud Super App as a Service

Release Notes and Announcements
Announcement: Tencent Cloud Mini Program Platform Renamed to Tencent Cloud Super App as a Service on January 2, 2025
Console Updates
Android SDK Updates
iOS SDK Updates
Flutter SDK Updates
IDE Updates
Base Library Updates
Product Introduction
Overview
Strengths
Use Cases
Purchase Guide
Billing Overview
Pay-As-You-Go Billing
Renewal Guide
Service Suspension Instructions
Getting Started
Plan Management
Overview
Console Account Management
Storage Configuration
Acceleration Configuration
Branding Configurations
Platform Features
Console Login
Users and Permission System
Mini Program Management
Mini Game Management
Superapp Management
Commercialization
Platform Management
User Management
Team Management
Operations Management
Security Center
Code Integration Guide
Getting Demo and SDK
Android
iOS
Flutter
Superapp Server
GUID Generation Rules
Mini Program Development Guide
Mini Program Introduction and Development Environment
Mini Program Code Composition
Guide
Framework
Components
API
Server Backend
JS SDK
Base Library
IDE Operation Instructions
Mini Game Development Guide
Guide
API
Server Backend
Practice Tutorial
Mini Program Login Practical Tutorial
Mini Program Subscription Message Practical Tutorial
Payment Practical Tutorial
Ad Integration Practical Tutorial
Mini Game Subscription Message Practical Tutorial
API Documentation
History
Introduction
API Category
Making API Requests
Operation Management APIs
User Management APIs
Team Management APIs
Sensitive API-Related APIs
Role Management APIs
Platform Management APIs
Other Console APIs
Mini Program or Mini Game APIs
Management-Sensitive APIs
Global Domain Management APIs
Superapp APIs
Data Types
Agreements
Service Level Agreement
Data Processing and Security Agreement
SDK Privacy Policy Module
SDK Data Processing and Security Agreement Module

App

PDF
Focus Mode
Font Size
Last updated: 2025-03-20 18:01:55

App(Object object)

Sign up for the Mini Program. Take one. Object Parameter that specifies the lifecycle callbacks of Mini Programs, and so on.
App() Must be app.js Must be called and can be called only once. Or there will be unforeseen consequences.

parameter

Object object
attribute
type
default
required
Introductions
onLaunch
function
-
no
Lifecycle callback--Monitor Mini Program initialization.
onShow
function
-
no
Lifecycle callback--Monitor Mini Program start or swicth to the frontend.
onHide
function
-
no
Lifecycle callback--Monitor Mini Program swicth to the backend.
onError
function
-
no
Error listener.
function
-
no
There is no listener function on the page.
function
-
no
Untreated Promise Rejects event listener functions.
function
-
no
Monitor subject changes
Other
any
-
no
Developers can add any function or data variable to Object Parameter, with the this Can access
For the definition of Mini Programs and the mechanism for running Mini Programs, see Operation mechanism.

onLaunch(Object object)

Mini Program initialization is completed when the trigger, the global trigger only once. Parameters can also be used wx.getLaunchOptionsSync Get.
parameter: With wx.getLaunchOptionsSync Agreement

onShow(Object object)

Mini Program start, or from the background into the foreground triggered when the display. You can also use wx.onAppShow Bind listening.
parameter: With wx.onAppShow Agreement

onHide()

Triggered when the Mini Program enters the background from the foreground. You can also use wx.onAppHide Bind listening.

onError(String error)

Script error or API Triggered on an error call. You can also use wx.onError Bind listening.
parameter: With wx.onError Agreement

onPageNotFound(Object object)

Triggered when the page the Mini Program is trying to open does not exist. You can also use wx.onPageNotFound Bind listening. Attention please refer to wx.onPageNotFound.
parameter: With wx.onPageNotFound Agreement
Sample code:
App({
onPageNotFound(res) {
wx.redirectTo({
url: 'pages/...'
}) // If it were Tabs Page, use the wx.switchTab
}
})

onUnhandledRejection(Object object)

Mini Programs have unhandled Promise Triggered when rejected. You can also use wx.onUnhandledRejection Bind listening. Attention please refer to wx.onUnhandledRejection.
parameter: With wx.onUnhandledRejection Agreement

onThemeChange(Object object)

Triggered when the system switches topics. You can also use wx.onThemeChange Bind listening.
parameter: With wx.onThemeChange Agreement
The translations are provided by WeChat Translation and are for reference only. In case of any inconsistency and discrepancy between the Chinese version and the English version, the Chinese version shall prevail.Incorrect translation.

Sample code:

App({
onLaunch (options) {
// Do something initial when launch.
},
onShow (options) {
// Do something when show.
},
onHide () {
// Do something when hide.
},
onError (msg) {
console.log(msg)
},
globalData: 'I am global data'
})

AppObject getApp(Object object)

Gets the Mini Programs globally unique App Instance.

parameter

Object object
attribute
type
default
required
Introductions
allowDefault
boolean
false
no
in App Returns the default implementation when undefined. When the app is invoked, properties defined in the default implementation are overridden and incorporated into the app. Generally usedIndependent subcontracting

Sample code

// other.js
var appInstance = getApp()
console.log(appInstance.globalData) // I am global data

Be careful

Don't define App() Or call the App Precall getApp() , using this You can ge it. app Instance;
adopt getApp() Do not privately call the lifecycle function after obtaining the instance.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback