From 97155cf5dcb0f1bf6263b442341a0e8a40f8e1c1 Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Fri, 30 Jun 2023 10:08:37 +0800
Subject: [PATCH] feat: page lifecycle
---
App.vue | 153 +++++++++++---------
pages.json | 5 +
pages/index.uvue | 17 +--
pages/page-lifecycle/page-lifecycle.test.js | 41 ++++++
pages/page-lifecycle/page-lifecycle.uvue | 41 ++++++
store/index.uts | 10 ++
6 files changed, 184 insertions(+), 83 deletions(-)
create mode 100644 pages/page-lifecycle/page-lifecycle.test.js
create mode 100644 pages/page-lifecycle/page-lifecycle.uvue
create mode 100644 store/index.uts
diff --git a/App.vue b/App.vue
index 11756b6..ee151ba 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 cc1fbb6..a2aa0d7 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 e04ec1c..4d7162b 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 0000000..15910ae
--- /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 0000000..bc5bdc4
--- /dev/null
+++ b/pages/page-lifecycle/page-lifecycle.uvue
@@ -0,0 +1,41 @@
+
+
+ page lifecycle
+
+
+
+
\ No newline at end of file
diff --git a/store/index.uts b/store/index.uts
new file mode 100644
index 0000000..458eb06
--- /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
--
GitLab