component-options.uvue 1016 字节
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3
<template>
  <view class="page">
    <text class="mb-10">component lifecycle 选项式 API</text>
4 5 6
    <keep-alive>
      <component :is="aliveComponent" />
    </keep-alive>
7 8
    <button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
    <button class="mt-10" @click="navigateToHome">navigateTo home</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10 11 12 13 14 15 16 17
  </view>
</template>

<script lang='uts'>
import ChildComponent from './ChildComponentOptions.uvue'
import { state } from '@/store/index.uts'

export default {
  components: { ChildComponent },
18 19 20 21 22
  data(){
    return {
      aliveComponent: ChildComponent as any | null,
    }
  },
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26 27
  methods: {
    // 自动化测试
    getLifeCycleNum(): number {
      return state.lifeCycleNum
    },
28 29
    toggleAliveComponent(){
      this.aliveComponent = this.aliveComponent == null ? ChildComponent : null
30 31 32 33 34
    },
    navigateToHome() {
      uni.navigateTo({
        url: '/pages/index/index'
      })
35
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38
  },
}
</script>