get-current-pages.uvue 1.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3
  <view>
    <page-head title="getCurrentPages"></page-head>
4 5
    <view class="uni-padding-wrap">
      <button @click="_getCurrentPages">getCurrentPages</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
6
      <view v-if="pages.length" style="padding: 15px 0px">
7 8
        <text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
        <template v-for="(page, index) in pages" :key="page.route">
H
hdx 已提交
9
          <text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
10 11
        </template>
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13
    </view>
  </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
14
</template>
DCloud-WZF's avatar
DCloud-WZF 已提交
15

H
hdx 已提交
16 17 18 19
<script>
  class Page {
    constructor(public route : string) {
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
20
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
21

H
hdx 已提交
22 23 24 25 26
  export default {
    data() {
      return {
        checked: false,
        pages: [] as Page[],
DCloud-WZF's avatar
DCloud-WZF 已提交
27
      }
H
hdx 已提交
28 29 30 31 32 33 34 35
    },
    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
DCloud-WZF's avatar
DCloud-WZF 已提交
36
        }
H
hdx 已提交
37 38 39 40 41 42 43
        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
          }
        }
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
44
    },
H
hdx 已提交
45
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
46
</script>