# getApp()

# # Return value

Type
any

# # See also

Related Bug

# # Example

hello uni-app x

<template>
 <view>
   <page-head title="getApp"></page-head>
   <view class="uni-padding-wrap">
     <text>点击按钮调用 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, 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)
   },
 },
}
</script>

以上示例,getApp()后调用了app.uvue里定义的increasetLifeCycleNum方法。app.uvue的源码另见

# # General type

# # GeneralCallbackResult

name type optinal default description
errMsg string YES - 错误信息