component-lifecycle.uvue 1.5 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12
  <!-- #ifdef APP -->
  <scroll-view style="flex:1">
  <!-- #endif -->
    <view class="pag container">
      <text class="uni-common-mb">component lifecycle</text>
      <component-lifecycle class="component-lifecycle" @updateIsScroll="updateIsScroll" />
      <button class="uni-common-mt" @click="scrollToBottom">scrollToBottom</button>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
13 14 15
</template>

<script setup>
雪洛's avatar
雪洛 已提交
16
  import ComponentLifecycle from '@/components/CompositionAPILifecycle.uvue'
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19 20
  import { state, setLifeCycleNum } from '@/store/index.uts'

  const isScrolled = ref(false)

21 22 23 24 25
  // 自动化测试
  const getLifeCycleNum = () : number => {
    return state.lifeCycleNum
  }

DCloud-WZF's avatar
DCloud-WZF 已提交
26 27 28 29 30 31 32 33 34 35 36
  // 自动化测试
  const pageSetlifeCycleNum = (num : number) => {
    setLifeCycleNum(num)
  }

  // 自动化测试
  const pullDownRefresh = () => {
    uni.startPullDownRefresh({
      success() {
        setTimeout(() => {
          uni.stopPullDownRefresh()
37
        }, 1500)
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
      },
    })
  }

  const scrollToBottom = () => {
    uni.pageScrollTo({
      scrollTop: 3000,
    })
  }

  const updateIsScroll = (val : boolean) => {
    isScrolled.value = val
  }

  // 自动化测试
  const getIsScrolled = () : boolean => {
    return isScrolled.value
  }

57
  defineExpose({
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60 61 62
    getLifeCycleNum,
    pageSetlifeCycleNum,
    pullDownRefresh,
    scrollToBottom,
    getIsScrolled
63
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65 66 67 68 69 70
</script>

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