Home > Article > Web Front-end > What is the usage of uni-app page?
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<code> | Element<code>$$ | ||
(selector: string) | <code><code>Get the page element array | Element[] | <code><code>waitFor |
(condition: string | number | Function | )<code><code><code>Wait until the condition is true | void | <code><code><code>data |
(path ?: String)<code><code><code><code>Get page rendering data | Object<code><code><code><code>setData | ||
<code><code><code>## (data: Object)<code><code><code><code><code>Set page rendering data | Object | <code><code><code><code>##size | |
<code><code>None<code><code><code><code><code><code>##Get the size of the page | Object<code><code><code><code>##scrollTop | ||
none<code><code><code><code><code><code><code><code> Get the page number scroll positionNumber | <code><code><code>## callMethod<code> | ||
#(method: string, ...args: any[]) | <code><code><code><code><code><code><code><code><code>Call the specified method on the pageany | <code><code><code>page.$() method <code>$() method is used Get the elements of the page. Input parameter description of $method: |
Required | Default value | Description | selector | String is |
Selector<code> | 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' | page.$$() method$ The $() method is used to obtain the page number element array. Input parameter description of $$ method: |
Required | ##Default value | Description | selector | Stringis | ||||||||||||||||||||||||||||||||||||||||||||||||||
<code> |
字段 | 类型 | 必填 | 默认值 | 说明 |
<code>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()方法参数如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
<code>path | String | 否 | 数据路径 |
示例代码如下:
1 const page = await program.currentPage(); 2 console.log(await page.data('list'));
setData()方法用于设置页面的渲染数据。setData()方法参数如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
<code>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()的参数说明如下:
字段 | 类型 | 必填 | 默认值 | 说明 |
<code>method | String | 是 | - | 需要调用的方法名 |
<code>...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!