page-lifecycle.uvue 2.3 KB
Newer Older
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex:1" :bounces="false">
4 5 6 7 8 9 10 11 12 13
  <!-- #endif -->
    <view class="page container">
      <text>page lifecycle</text>
      <button class="uni-common-mt" @click="scrollToBottom">scrollToBottom</button>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

14 15 16 17
<script setup>
  import { state, setLifeCycleNum } from '@/store/index.uts'
  
  const isScrolled = ref(false)
18 19
  
  onLoad((_: OnLoadOptions) => {
20
    // 自动化测试
21 22 23
    setLifeCycleNum(state.lifeCycleNum + 100)
  })
  onPageShow(() => {
24
    // 自动化测试
25 26
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
27 28
  onReady(() => {
    // 自动化测试
29 30 31
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  onPullDownRefresh(() => {
32
    // 自动化测试
33 34
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
35
  onPageScroll((_) => {
36 37 38
    // 自动化测试
    isScrolled.value = true
  })
39
  onReachBottom(() => {
40 41 42
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
43 44 45
  onBackPress((_: OnBackPressOptions): boolean | null => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 10)
46 47
    return null
  })
48
  onPageHide(() => {
49 50 51
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 10)
  })
52
  onUnload(() => {
53 54 55 56
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 100)
  })
  onResize((_) => {
57
    // 自动化测试
58
    setLifeCycleNum(state.lifeCycleNum + 10)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  })
  
  // 自动化测试
  const getLifeCycleNum = () : number => {
    return state.lifeCycleNum
  }
  // 自动化测试
  const pageSetLifeCycleNum = (num: number) => {
    setLifeCycleNum(num)
  }
 
  // 自动化测试
  const pullDownRefresh = () => {
    uni.startPullDownRefresh({
      success() {
        setTimeout(() => {
          uni.stopPullDownRefresh()
        }, 1500)
      },
    })
  }
80 81 82 83 84
  
  const scrollToBottom = () => {
    uni.pageScrollTo({
      scrollTop: 2000,
    })
85 86 87 88 89 90 91 92 93 94 95 96 97
  }
  
  // 自动化测试
  const getIsScrolled = (): boolean => {
    return isScrolled.value
  }
  
  defineExpose({
    getLifeCycleNum,
    pageSetLifeCycleNum,
    pullDownRefresh,
    scrollToBottom,
    getIsScrolled
98 99 100 101 102 103 104 105
  })
</script>

<style>
  .container {
    height: 1200px;
  }
</style>