component-options.uvue 845 字节
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 7
    <keep-alive>
      <component :is="aliveComponent" />
    </keep-alive>
    <button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
8 9 10 11 12 13 14 15 16
  </view>
</template>

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

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