English
getCurrentPages()
函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,数组中的元素为页面实例,第一个元素为首页,最后一个元素为当前页面。
Type |
---|
Array<BasePage> |
name | type | optinal | default | description |
---|---|---|---|---|
route | string | YES | - | - |
options | Map<string, string | null> | YES | - | - |
<template>
<view>
<page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px"
>index: {{ index }}, route: {{ page.route }}</text
>
</template>
</view>
</view>
</view>
</template>
<script lang="uts">
class Page {
constructor(public route : string) {
}
}
export default {
data() {
return {
checked: false,
pages: [] as Page[],
}
},
methods: {
_getCurrentPages: function () {
this.pages.length = 0
const pages = getCurrentPages()
this.pages.push(new Page(pages[0].route))
if (this.pages[0].route.includes('/tabBar/')) {
this.checked = true
}
for (let i = 1; i < pages.length; i++) {
this.pages.push(new Page(pages[i].route))
if (pages[i].route.includes('/tabBar/')) {
this.checked = false
}
}
},
},
}
</script>
name | type | optinal | default | description |
---|---|---|---|---|
errMsg | string | YES | - | 错误信息 |