Skip to content

Commit 25e569d

Browse files
author
wangcuijuan
committed
去掉getCurrentPages文档部分
1 parent 3155c23 commit 25e569d

1 file changed

Lines changed: 0 additions & 31 deletions

File tree

docs-vitepress/api/global-api.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -320,37 +320,6 @@ if (__mpx_mode__ === 'web') {
320320
}
321321
```
322322

323-
## getCurrentPages
324-
getCurrentPages() 获取当前页面栈。数组中第一个元素为首页,最后一个元素为当前页面。
325-
326-
#### 基础用法
327-
```js
328-
// 获取页面栈数组(按栈顺序排列,最后一个元素为当前页面)
329-
const pages = getCurrentPages();
330-
const currentPage = pages[pages.length - 1]; // 当前页实例
331-
332-
// 示例:获取当前页面路径和参数
333-
console.log('当前页面路径:', currentPage.route); // 输出如 'pages/home/index'
334-
console.log('页面参数:', currentPage.options); // 输出 onLoad 中的 query 对象
335-
```
336-
#### 获取上一页实例
337-
338-
```js
339-
const pages = getCurrentPages();
340-
const prevPage = pages[pages.length - 2]; // 上一页实例
341-
if (prevPage) {
342-
console.log('上一页路径:', prevPage.route);
343-
// 调用上一页方法(需确保方法存在)
344-
prevPage.someMethod?.();
345-
}
346-
```
347-
::: tip 注意
348-
注意事项
349-
不要尝试修改页面栈,会导致路由以及页面状态错误。
350-
351-
不要在 App.onLaunch 的时候调用 getCurrentPages(),此时 page 还没有生成。
352-
:::
353-
354323
## 内建生命周期变量 {#built-in-lifecycle-variable}
355324
Mpx 在运行时自身有着一套内建生命周期,当开发者想使用内建生命周期时,可以通过内建生命周期变量进行对应生命周期的注册,
356325
需要注意的是,这部分内建生命周期变量**只能用于选项式 API**

0 commit comments

Comments
 (0)