navigator.uvue 3.5 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
	<view>
		<page-head title="navigate"></page-head>
		<view class="uni-padding-wrap uni-common-mt">
			<view style="flex-direction: row">
				<text style="width: 170px">onLoad触发时间戳:</text>
				<text style="text-align: right">{{ onLoadTime }}</text>
			</view>
			<view style="flex-direction: row">
				<text style="width: 170px">onReady触发时间戳:</text>
				<text style="text-align: right">{{ onReadyTime }}</text>
			</view>
			<view style="flex-direction: row">
				<text style="width: 170px">onUnload触发时间戳:</text>
				<text style="text-align: right">见控制台</text>
			</view>
			<view style="flex-direction: row">
				<text style="width: 170px">onShow触发时间戳:</text>
				<text style="text-align: right">{{ onShowTime }}</text>
			</view>
			<view style="flex-direction: row">
				<text style="width: 170px">onHide触发时间戳:</text>
				<text style="text-align: right">{{ onHideTime }}</text>
			</view>
			<text>onBackPress触发时间戳:见控制台</text>
			<!-- <view style="flex-direction: row">
				<text style="width: 170px">onBackPress触发时间戳:</text>
				<text style="text-align: right">见控制台</text>
			</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 已提交
44 45
</template>
<script lang="ts">
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	import { setLifeCycleNum, state } from '@/store/index.uts'
	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()
			console.log('onHide', Date.now())
		},
		onUnload() {
			console.log('onUnLoad', Date.now())
		},
		/* onBackPress() {
			console.log('onBackPress', Date.now()) // 为何不生效???
			// 要把event也打出来
		}, */
		methods: {
			navigateTo() {
				uni.navigateTo({
					url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
				})
			},
			navigateBack() {
				uni.navigateBack({
					delta: 1,
				})
			},
			redirectTo() {
				uni.redirectTo({
					url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
				})
			},
			switchTab() {
				uni.switchTab({
					url: '/pages/tabBar/template',
				})
			},
			reLaunch() {
				uni.reLaunch({
					url: '/pages/tabBar/component',
				})
			},
			customAnimation() {
				uni.navigateTo({
					url: '/pages/API/navigator/new-page/new-uvue-page-1?data=使用自定义动画打开页面',
					animationType: 'slide-in-bottom',
					animationDuration: 200,
				})
			},
			setLifeCycleNum(num : number) {
				setLifeCycleNum(num)
			},
			getLifeCycleNum() : number {
				return state.lifeCycleNum
			},
		},
	}
</script>