Skip to main content

page instance

The current page instance is accessed via $w.page and can be quickly referenced using $page.

Properties

id: string

current page id

label: string

current page name

path: string

The path of the current page, assuming the current page is the one with id home in the main package:

  1. In a web application, access the value /home
  2. Access the value pages/miniapp/index in the Mini Program

dataset: pagedataset

Page Data Object

handler: Object

The page defines low-code handler methods, accessible via $w.page.handler.<handler name>.

Methods

$w.page.setState

$w.page.setState(data: object): void

Feature Description

Setting the value of $w.page.dataset.state uses the key of the passed object as a path and, in the order of the keys, sets the value at the corresponding path in $w.page.dataset.state to the value of the object. Properties that do not exist will be created, and other properties will not be modified.

Input Parameters

NameTypeDescription
dataobjectAn object with the path as the key and the new value as the value

An Object is represented in the form of key: value, which changes the value corresponding to the key in $w.page.dataset.state to the value.

The key can be provided as a data path, allowing modification of specific items in an array or properties of an object, for example array.2.message, a.b.c.d.

Example

console.log($w.page.dataset.state.data);
// undefined
$w.page.setState({"data.inner": {test: 'data'}})
console.log($w.page.dataset.state.data);
/**
* {
* inner: {
* test: "data"
* }
* }
* /

$w.page.setParams

$w.page.setState(params: object): void

Feature Description

Setting the value of $w.page.dataset.params uses the key of the passed object as a path and, in the order of the keys, sets the value at the corresponding path in $w.page.dataset.state to the value of the object. Properties that do not exist will be created, and other properties will not be modified.

In the web scenario, the current URL address is modified in sync and the current route is replaced (equivalent to triggering $w.utils.redirectTo({pageId:"currentPageId", params})). This capability allows parameters to be persisted in the URL, enabling state maintenance based on URL parameters during page navigation or when going back.

Input Parameters

NameTypeDescription
paramsobjectAn object with the path as the key and the new value as the value

An Object is represented in the form of key: value, which changes the value corresponding to the key in $w.page.dataset.params to the value.

The key can be provided as a data path, allowing modification of specific items in an array or properties of an object, for example array.2.message, a.b.c.d.

Example

console.log($w.page.dataset.state.params);
// undefined
$w.page.setState({"data.inner": {test: 'data'}})
console.log($w.page.dataset.params.data);
/**
* {
* inner: {
* test: "data"
* }
* }
* /

PageDataset

NameTypeDescription
stateobjectPage variable, accessed and assigned via $w.page.dataset.state.xxx
paramsobjectPage Url parameters, accessible in read-only mode via $w.page.dataset.params.xxx