get-app.uvue 972 字节
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4
  <view>
    <page-head title="getApp"></page-head>
    <view class="uni-padding-wrap">
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6
      <text>点击按钮调用 App.uvue methods</text>
      <text class="margin-top:6px;">increasetLifeCycleNum 方法</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
7 8 9
      <button class="uni-common-mt" @click="_increasetLifeCycleNum">
        increase lifeCycleNum
      </button>
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12
      <text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
    </view>
  </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
13
</template>
DCloud-WZF's avatar
DCloud-WZF 已提交
14

DCloud-WZF's avatar
DCloud-WZF 已提交
15 16 17
<script lang="uts">
import { State, state, setLifeCycleNum } from '@/store/index.uts'

DCloud-WZF's avatar
DCloud-WZF 已提交
18
export default {
DCloud-WZF's avatar
DCloud-WZF 已提交
19
	data() {
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    return {
DCloud-WZF's avatar
DCloud-WZF 已提交
21
			_state: state as State,
DCloud-WZF's avatar
DCloud-WZF 已提交
22 23 24 25 26 27 28 29 30 31 32 33
      lifeCycleNum: 0,
    }
	},
	onReady() {
		this.lifeCycleNum = state.lifeCycleNum
	},
  methods: {
    _increasetLifeCycleNum: function () {
      const app = getApp()
      app.increasetLifeCycleNum()
      this.lifeCycleNum = state.lifeCycleNum
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36 37
    // 自动化测试
    setLifeCycleNum(num: number) {
      setLifeCycleNum(num)
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39
  },
}
DCloud-WZF's avatar
DCloud-WZF 已提交
40
</script>