get-app.uvue 1.7 KB
Newer Older
1 2 3 4 5 6
<template>
  <view>
    <page-head title="getApp"></page-head>
    <view class="uni-padding-wrap">
      <button @click="getGlobalData">
        get globalData
DCloud-WZF's avatar
DCloud-WZF 已提交
7
      </button>
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
      <template v-if="globalDataStr">
      <text class="uni-common-mt">globalData str: {{ globalDataStr }}</text>
      <text class="uni-common-mt">globalData num: {{ globalDataNum }}</text>
      <text class="uni-common-mt">globalData boolean: {{ globalDataBool }}</text>
      </template>
      <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>
</template>

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

  export default {
    data() {
      return {
        globalDataStr: '',
        globalDataNum: 0,
        globalDataBool: false,
        lifeCycleNum: 0,
      }
    },
    onReady() {
      this.lifeCycleNum = state.lifeCycleNum
    },
    methods: {
      getGlobalData() {
        const app = getApp()
        this.globalDataStr = app.globalData.str
        this.globalDataNum = app.globalData.num
        this.globalDataBool = app.globalData.bool
      },
      _increasetLifeCycleNum: function () {
        const app = getApp()
        app.increasetLifeCycleNum()
        this.lifeCycleNum = state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num : number) {
        setLifeCycleNum(num)
      }
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
56
</script>