uni-app page module provides methods to control the page. The usage methods are: 1. "page.$('.index-desc')"; 2. "page.$$('.list- text')"; 3. "await page.waitFor('picker')" and so on.
The operating environment of this article: Windows 7 system, uni-app version 2.5.1, DELL G3 computer
Usage of uni-app page What is it?
Page of uni-app——Methods to control the page
Page module provides methods to control the page.
Properties | Description | Return type |
Page path | String | |
Page parameters | Object | |
Rendering data of the page | Object |
Method | Parameters | ##Description | Return value | ##$
Get page elements
| Element $$ | ||
(selector: string) |
| Element[] | waitFor |
(condition: string | number | Function | )
| void | data |
(path ?: String)
| Object setData | ||
| Object |
| |
| Object
| ||
none Number |
| ||
#(method: string, ...args: any[]) |
|
|
Required | Default value | Description | selector | String is |
Selector
| The sample code is as follows: | 1 const page = await program.currentPage() 2 const element = await page.$('.index-desc') 3 console.log(element.tagName) // 'view' Copy after login | page.$$() method$ The $() method is used to obtain the page number element array. Input parameter description of $$ method: |
Required | ##Default value | Description | selector | Stringis | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
字段 | 类型 | 必填 | 默认值 | 说明 |
condition | String Number Function | 是 | 等待条件 |
示例代码如下:
1 const page = await program.currentPage() await page.waitFor(5000) // 等待 5 秒 2 await page.waitFor('picker') // 等待页面中出现 picker 元素 3 await page.waitFor(async() = >{ 4 return (await page.$$('picker')).length > 5 5 }); // 等待页面中 picker 元素数量大于 5
data()方法用于获取页码数据。data()方法参数如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
path | String | 否 | 数据路径 |
示例代码如下:
1 const page = await program.currentPage(); 2 console.log(await page.data('list'));
setData()方法用于设置页面的渲染数据。setData()方法参数如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
data | Object | 是 | 要改变的数据 |
示例代码如下:
1 const page = await program.currentPage(); 2 await page.setData({ 3 text: 'changed data'4 });
size()方法获取页面的大小。size()的返回值如下:
字段 | 类型 | 说明 |
width | number | 页面可滚动宽度 |
height | number | 页面可滚动高度 |
callMethod()方法用于调用页面的指定方法。callMethod()的参数说明如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
method | String | 是 | - | 需要调用的方法名 |
...args | array | 否 | - | 方法参数 |
推荐学习:《uni-app教程》
The above is the detailed content of What is the usage of uni-app page?. For more information, please follow other related articles on the PHP Chinese website!