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:
- In a web application, access the value
/home - Access the value
pages/miniapp/indexin 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
| Name | Type | Description |
|---|---|---|
| data | object | An 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
| Name | Type | Description |
|---|---|---|
| params | object | An 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
| Name | Type | Description |
|---|---|---|
| state | object | Page variable, accessed and assigned via $w.page.dataset.state.xxx |
| params | object | Page Url parameters, accessible in read-only mode via $w.page.dataset.params.xxx |