1.0.8 • Published 1 year ago

@uni/application v1.0.8

Weekly downloads
65
License
BSD-3-Clause
Repository
github
Last release
1 year ago

application

npm

Application interface

Support

Install

$ npm install @uni/application --save

Function

getApp(): AppObject

Gets the globally unique App instance of the Mini Program.

getCurrentPages(): PageObject[]

Gets the current page stack. In the array, the first element is the homepage and the last element is the current page.

getLaunchOptionsSync(): LaunchObject

Obtains the parameters upon Mini Program startup.

onError(callback): void

Listens on the Mini Program error event. This event is triggered as a result of script error or failed API call.

Parameters

function callback The callback function for the Mini Program error event

Parameters

string error Error message, including stacks.

offError(callback): void

Un-listens on Mini Program error event.

Parameters

function callback The callback function for the Mini Program error event

onUnhandledRejection(callback): void

Listen for unhandled Promise rejection events.

Parameters

function callback The callback function for the Mini Program error event

Parameters

Object res |Property |Type |Description| |:--|:--|:--| |reason |string or Error| Reason for rejection, usually an Error object| |promise| Promise.|Rejected Promise object|

offUnhandledRejection(callback): void

Cancel listening for unhandled Promise rejection events.

Parameters

function callback The callback function for the Mini Program error event

Example

import { getApp, getCurrentPages, getLaunchOptionsSync, onError, offError } from '@uni/application';

const appInstance = getApp();
const currentPages = getCurrentPages();
const launchOptions = getLaunchOptionsSync();

onError(e => {
  console.log(e);
});

offError();

You can also import from the big package:

import { application } from '@uni/apis';

const appInstance = application.getApp();
const currentPages = application.getCurrentPages();
const launchOptions = application.getLaunchOptionsSync();

application.onError(e => {
  console.log(e);
});

application.offError();