navigator.uvue 4.9 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
2 3 4
  <view>
    <page-head title="navigate"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7
      <view class="direction-row">
        <text class="label">onLoad触发时间戳:</text>
        <text>{{ onLoadTime }}</text>
8
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10 11
      <view class="direction-row">
        <text class="label">onShow触发时间戳:</text>
        <text>{{ onShowTime }}</text>
12
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14 15
      <view class="direction-row">
        <text class="label">onReady触发时间戳:</text>
        <text>{{ onReadyTime }}</text>
16
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19
      <view class="direction-row">
        <text class="label">onHide触发时间戳:</text>
        <text>{{ onHideTime }}</text>
20
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22 23 24 25 26 27
      <view class="direction-row">
        <text class="label">onBackPress触发时间戳:</text>
        <text>见控制台</text>
      </view>
      <view class="direction-row">
        <text class="label">onUnload触发时间戳:</text>
        <text>见控制台</text>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
      </view>
      <view class="uni-btn-v">
        <button @tap="navigateTo" class="uni-btn">
          跳转新页面,并传递数据
        </button>
        <button @tap="navigateBack" class="uni-btn">返回上一页</button>
        <button @tap="redirectTo" class="uni-btn">在当前页面打开</button>
        <button @tap="switchTab" class="uni-btn">切换到模板选项卡</button>
        <button @tap="reLaunch" class="uni-btn">关闭所有页面,打开首页</button>
        <button @tap="customAnimation" class="uni-btn">
          使用自定义动画打开页面
        </button>
      </view>
    </view>
  </view>
Y
init  
yurj26 已提交
43 44
</template>
<script lang="ts">
DCloud-WZF's avatar
DCloud-WZF 已提交
45
import { state, setLifeCycleNum } from '@/store/index.uts'
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
export default {
  data() {
    return {
      onLoadTime: 0,
      onShowTime: 0,
      onReadyTime: 0,
      onHideTime: 0,
    }
  },
  onLoad() {
    this.onLoadTime = Date.now()
    console.log('onLoad', this.onLoadTime)
  },
  onShow() {
    this.onShowTime = Date.now()
    console.log('onShow', this.onShowTime)
  },
  onReady() {
    this.onReadyTime = Date.now()
    console.log('onReady', this.onReadyTime)
  },
  onHide() {
    this.onHideTime = Date.now()
DCloud-WZF's avatar
DCloud-WZF 已提交
69 70 71 72 73 74
    console.log('onHide', this.onHideTime)
  },
  onBackPress(options: OnBackPressOptions): boolean | null {
    console.log('onBackPress', Date.now())
    console.log('onBackPress from', options.from)
    return null
75 76
  },
  onUnload() {
DCloud-WZF's avatar
DCloud-WZF 已提交
77
    console.log('onUnload', Date.now())
78 79 80 81
  },
  methods: {
    navigateTo() {
      uni.navigateTo({
DCloud-WZF's avatar
DCloud-WZF 已提交
82 83 84 85 86 87 88 89 90 91
        url: '/pages/API/navigator/new-page/new-page?data=Hello',
        success(result) {
          console.log('navigateTo success', result.errMsg)
        },
        fail(error) {
          console.log('navigateTo fail', error.errMsg)
        },
        complete(result) {
          console.log('navigateTo complete', result.errMsg)
        },
92 93 94 95
      })
    },
    navigateBack() {
      uni.navigateBack({
DCloud-WZF's avatar
DCloud-WZF 已提交
96 97 98 99 100 101 102 103 104
        success(result) {
          console.log('navigateBack success', result.errMsg)
        },
        fail(error) {
          console.log('navigateBack fail', error.errMsg)
        },
        complete(result) {
          console.log('navigateBack complete', result.errMsg)
        },
105 106 107 108
      })
    },
    redirectTo() {
      uni.redirectTo({
DCloud-WZF's avatar
DCloud-WZF 已提交
109 110 111 112 113 114 115 116 117 118
        url: '/pages/API/navigator/new-page/new-page?data=Hello',
        success(result) {
          console.log('redirectTo success', result.errMsg)
        },
        fail(error) {
          console.log('redirectTo fail', error.errMsg)
        },
        complete(result) {
          console.log('redirectTo complete', result.errMsg)
        },
119 120 121 122 123
      })
    },
    switchTab() {
      uni.switchTab({
        url: '/pages/tabBar/template',
DCloud-WZF's avatar
DCloud-WZF 已提交
124 125 126 127 128 129 130 131 132
        success(result) {
          console.log('switchTab success', result.errMsg)
        },
        fail(error) {
          console.log('switchTab fail', error.errMsg)
        },
        complete(result) {
          console.log('switchTab complete', result.errMsg)
        },
133 134 135 136 137
      })
    },
    reLaunch() {
      uni.reLaunch({
        url: '/pages/tabBar/component',
DCloud-WZF's avatar
DCloud-WZF 已提交
138 139 140 141 142 143 144 145 146
        success(result) {
          console.log('reLaunch success', result.errMsg)
        },
        fail(error) {
          console.log('reLaunch fail', error.errMsg)
        },
        complete(result) {
          console.log('reLaunch complete', result.errMsg)
        },
147 148 149 150
      })
    },
    customAnimation() {
      uni.navigateTo({
DCloud-WZF's avatar
DCloud-WZF 已提交
151
        url: '/pages/API/navigator/new-page/new-page?data=自定义动画打开页面',
152 153 154 155
        animationType: 'slide-in-bottom',
        animationDuration: 200,
      })
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
156
    // 自动化测试
157 158 159
    getLifeCycleNum(): number {
      return state.lifeCycleNum
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
160 161 162 163
    // 自动化测试
    setLifeCycleNum(num: number) {
      setLifeCycleNum(num)
    },
164 165 166
  },
}
</script>
DCloud-WZF's avatar
DCloud-WZF 已提交
167 168 169 170 171 172 173 174 175

<style>
.direction-row {
  flex-direction: row;
}
.label {
  width: 190px;
}
</style>