diff --git a/App.vue b/App.vue index 11756b668c9f0de14b87fbf6005fbc61e6515ed1..ee151ba2bd3fea132bcf1a7f63e1275b7401047e 100644 --- a/App.vue +++ b/App.vue @@ -1,94 +1,103 @@ - \ No newline at end of file diff --git a/pages.json b/pages.json index cc1fbb62d48a4a3b045e15a1402555e8b40d5ffa..a2aa0d768d3fe70ce955fa24a6f402684bb2e491 100644 --- a/pages.json +++ b/pages.json @@ -52,6 +52,11 @@ "style": { "navigationBarTitleText": "v-slot" } + },{ + "path": "pages/page-lifecycle/page-lifecycle", + "style": { + "navigationBarTitleText": "page-lifecycle" + } } ], "globalStyle": { diff --git a/pages/index.uvue b/pages/index.uvue index e04ec1c7df996f07d6e18b422c04cf620fa361a5..4d7162b90dd7debc2abd1c5f70e43f72ba3bc57c 100644 --- a/pages/index.uvue +++ b/pages/index.uvue @@ -16,6 +16,7 @@ diff --git a/pages/page-lifecycle/page-lifecycle.test.js b/pages/page-lifecycle/page-lifecycle.test.js new file mode 100644 index 0000000000000000000000000000000000000000..15910aed53087bd03ef763c6131ad1b996b6c597 --- /dev/null +++ b/pages/page-lifecycle/page-lifecycle.test.js @@ -0,0 +1,41 @@ +const PAGE_PATH = '/pages/page-lifecycle/page-lifecycle' +const HOME_PATH = '/pages/index' + +describe('page-lifecycle', () => { + let page + let lifeCycleNum + beforeAll(async () => { + page = await program.reLaunch(PAGE_PATH) + await page.waitFor(1000) + }) + it('onLoad onShow onReady', async () => { + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1220) + }) + it('onHide', async () => { + page = await program.navigateTo(HOME_PATH) + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1210) + page = await program.navigateBack() + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1220) + }) + it('onUnload', async () => { + page = await program.redirectTo(HOME_PATH) + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1120) + }) + it('onBackPress', async () => { + page = await program.navigateTo(PAGE_PATH) + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1240) + page = await program.navigateBack() + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(1130) + }) + it('onLastPageBackPress', async () => { + page = await program.navigateBack() + lifeCycleNum = await page.callMethod('getLifeCycleNum') + expect(lifeCycleNum).toBe(130) + }) +}) \ No newline at end of file diff --git a/pages/page-lifecycle/page-lifecycle.uvue b/pages/page-lifecycle/page-lifecycle.uvue new file mode 100644 index 0000000000000000000000000000000000000000..bc5bdc4373e1daddee3ff07f57af374f080ea071 --- /dev/null +++ b/pages/page-lifecycle/page-lifecycle.uvue @@ -0,0 +1,41 @@ + + + \ No newline at end of file diff --git a/store/index.uts b/store/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..458eb06334ac01e0d67652fc768d422713911ef2 --- /dev/null +++ b/store/index.uts @@ -0,0 +1,10 @@ +export type State = { + lifeCycleNum: number +} +export const state = reactive({ + lifeCycleNum: 0 +} as State) + +export const setLifeCycleNum = (num: number) => { + state.lifeCycleNum = num +} \ No newline at end of file