提交 467abdea 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat: getApp

上级 43c39f79
...@@ -35,6 +35,12 @@ export default { ...@@ -35,6 +35,12 @@ export default {
console.log('App LastPageBackPress') console.log('App LastPageBackPress')
return null return null
}, },
methods: {
increasetLifeCycleNum() {
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App increasetLifeCycleNum')
}
}
} }
</script> </script>
......
...@@ -4,8 +4,9 @@ describe('getApp', () => { ...@@ -4,8 +4,9 @@ describe('getApp', () => {
it('getApp', async () => { it('getApp', async () => {
const page = await program.navigateTo(PAGE_PATH) const page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000) await page.waitFor(1000)
await page.callMethod('_getApp') const oldData = await page.data()
const data = await page.data() await page.callMethod('_increasetLifeCycleNum')
expect(data.checked).toBe(true) const newData = await page.data()
expect(newData.lifeCycleNum - oldData.lifeCycleNum).toBe(100)
}) })
}) })
<template> <template>
<view> <view>
<page-head title="getApp"></page-head> <page-head title="getApp"></page-head>
<button @click="_getApp">getApp</button> <view class="uni-padding-wrap">
</view> <button @click="_increasetLifeCycleNum">increase lifeCycleNum</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
</view>
</view>
</template> </template>
<script> <script lang="ts">
export default { import { state } from '@/store/index.uts'
data() { export default {
return { data() {
checked: false return {
} lifeCycleNum: 0,
}, }
methods: { },
_getApp: function () { onReady() {
// const app = getApp() this.lifeCycleNum = state.lifeCycleNum
this.checked = true },
} methods: {
} _increasetLifeCycleNum: function () {
} const app = getApp()
app.increasetLifeCycleNum()
this.lifeCycleNum = state.lifeCycleNum
},
},
}
</script> </script>
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
{ {
name: "getApp", name: "getApp",
url: "get-app", url: "get-app",
enable: false
}, },
{ {
name: "getCurrentPages", name: "getCurrentPages",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册