get-app.uvue 1.2 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3 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
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex:1;padding-bottom: 20px;">
  <!-- #endif -->
    <view>
      <page-head title="getApp"></page-head>
      <view class="uni-padding-wrap">
        <text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
        <text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
        <button class="uni-common-mt" @click="_increasetLifeCycleNum">
          increase lifeCycleNum
        </button>
        <text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
  import { state, setLifeCycleNum } from '@/store/index.uts'

  export default {
    data() {
      return {
        lifeCycleNum: 0,
      }
    },
    onReady() {
      this.lifeCycleNum = state.lifeCycleNum
    },
    methods: {
      _increasetLifeCycleNum: function () {
        const app = getApp()
        app.increasetLifeCycleNum()
        this.lifeCycleNum = state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      }
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
44
  }
雪洛's avatar
雪洛 已提交
45 46 47 48 49 50 51
</script>

<style>
  .bold {
    font-weight: bold;
  }
  .hr{border-bottom: 1px solid #ccc;}
DCloud-WZF's avatar
DCloud-WZF 已提交
52
</style>