page-lifecycle.uvue 2.2 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 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  <!-- #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>

<script setup>
  import { state, setLifeCycleNum } from '@/store/index.uts'
  
  const isScrolled = ref(false)
  
  onLoad((_: OnLoadOptions) => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 100)
  })
  onPageShow(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  onReady(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  onPullDownRefresh(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  onPageScroll((_) => {
    // 自动化测试
    isScrolled.value = true
  })
  onReachBottom(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  onBackPress((_: OnBackPressOptions): boolean | null => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 10)
    return null
  })
  onPageHide(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 10)
  })
  onUnload(() => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum - 100)
  })
  onResize((_) => {
    // 自动化测试
    setLifeCycleNum(state.lifeCycleNum + 10)
  })
  
  // 自动化测试
  const getLifeCycleNum = () : number => {
    return state.lifeCycleNum
  }
  // 自动化测试
DCloud-WZF's avatar
DCloud-WZF 已提交
66
  const pageSetLifeCycleNum = (num: number) => {
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
    setLifeCycleNum(num)
  }
 
  // 自动化测试
  const pullDownRefresh = () => {
    uni.startPullDownRefresh({
      success() {
        setTimeout(() => {
          uni.stopPullDownRefresh()
        }, 1000)
      },
    })
  }
  
  const scrollToBottom = () => {
    uni.pageScrollTo({
      scrollTop: 2000,
    })
  }
  
  // 自动化测试
  const getIsScrolled = (): boolean => {
    return isScrolled.value
  }
  
  defineExpose({
    getLifeCycleNum,
DCloud-WZF's avatar
DCloud-WZF 已提交
94
    pageSetLifeCycleNum,
95 96 97 98 99 100 101 102 103 104 105
    pullDownRefresh,
    scrollToBottom,
    getIsScrolled
  })
</script>

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