diff --git a/App.vue b/App.vue
index b3a23302bba3f88e743f0ce8a8f0c9cb4b0493c4..8a258cc6922f82ba5d319344f339a7ead61d129b 100644
--- a/App.vue
+++ b/App.vue
@@ -1,6 +1,8 @@
\ No newline at end of file
+ },
+ onLoad() {
+ this.onLoadTime = Date.now()
+ console.log('onLoad', this.onLoadTime)
+ },
+ onShow() {
+ this.onShowTime = Date.now()
+ console.log('onShow', this.onShowTime)
+ },
+ onReady() {
+ this.onReadyTime = Date.now()
+ console.log('onReady', this.onReadyTime)
+ },
+ onHide() {
+ this.onHideTime = Date.now()
+ console.log('onHide', Date.now())
+ },
+ onUnload() {
+ console.log('onUnLoad', Date.now())
+ },
+ methods: {
+ navigateTo() {
+ uni.navigateTo({
+ url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
+ })
+ },
+ navigateBack() {
+ uni.navigateBack({
+ delta: 1,
+ })
+ },
+ redirectTo() {
+ uni.redirectTo({
+ url: '/pages/API/navigator/new-page/new-uvue-page-1?data=Hello',
+ })
+ },
+ switchTab() {
+ uni.switchTab({
+ url: '/pages/tabBar/template',
+ })
+ },
+ reLaunch() {
+ uni.reLaunch({
+ url: '/pages/tabBar/component',
+ })
+ },
+ customAnimation() {
+ uni.navigateTo({
+ url: '/pages/API/navigator/new-page/new-uvue-page-1?data=使用自定义动画打开页面',
+ animationType: 'slide-in-bottom',
+ animationDuration: 200,
+ })
+ },
+ setLifeCycleNum(num: number) {
+ setLifeCycleNum(num)
+ },
+ getLifeCycleNum(): number {
+ return state.lifeCycleNum
+ },
+ },
+}
+
diff --git a/pages/API/page-lifecircle/page-lifecircle.uvue b/pages/API/page-lifecircle/page-lifecircle.uvue
deleted file mode 100644
index 739d568f43b9f868317e396e09b360db50ee8cad..0000000000000000000000000000000000000000
--- a/pages/API/page-lifecircle/page-lifecircle.uvue
+++ /dev/null
@@ -1,40 +0,0 @@
-
-
- onLoad触发时间
-
-
-
-
-
-
diff --git a/pages/API/page-lifecycle/page-lifecycle.test.js b/pages/API/page-lifecycle/page-lifecycle.test.js
new file mode 100644
index 0000000000000000000000000000000000000000..e106beef17f0e0deb51f5d9b4ec04d89f9030408
--- /dev/null
+++ b/pages/API/page-lifecycle/page-lifecycle.test.js
@@ -0,0 +1,55 @@
+const PAGE_PATH = '/pages/API/page-lifecycle/page-lifecycle'
+const INTERMEDIATE_PAGE_PATH = '/pages/API/navigator/navigator'
+
+describe('page-lifecycle', () => {
+ let page
+ let lifeCycleNum
+ beforeAll(async () => {
+ page = await program.reLaunch(INTERMEDIATE_PAGE_PATH)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(1100)
+
+ const initLifecycleNum = 0
+ await page.callMethod('setLifeCycleNum', initLifecycleNum)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(initLifecycleNum)
+
+ page = await program.reLaunch(PAGE_PATH)
+ await page.waitFor(1000)
+ })
+ it('onLoad onShow onReady', async () => {
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(120)
+ })
+ it('onHide', async () => {
+ page = await program.navigateTo(INTERMEDIATE_PAGE_PATH)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(110)
+ page = await program.navigateBack()
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(120)
+ })
+ it('onUnload', async () => {
+ page = await program.redirectTo(INTERMEDIATE_PAGE_PATH)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(20)
+ })
+ it('onBackPress', async () => {
+ page = await program.navigateTo(PAGE_PATH)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(140)
+ page = await program.navigateBack()
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(30)
+ })
+ it('onLastPageBackPress', async () => {
+ page = await program.navigateBack()
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(-970)
+
+ const resetLifecycleNum = 1100
+ await page.callMethod('setLifeCycleNum', resetLifecycleNum)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(resetLifecycleNum)
+ })
+})
diff --git a/pages/API/page-lifecycle/page-lifecycle.uvue b/pages/API/page-lifecycle/page-lifecycle.uvue
new file mode 100644
index 0000000000000000000000000000000000000000..c87a3b7c94771e0fc72df188fd3117438e0b700e
--- /dev/null
+++ b/pages/API/page-lifecycle/page-lifecycle.uvue
@@ -0,0 +1,41 @@
+
+
+ page lifecycle
+
+
+
+
diff --git a/store/index.uts b/store/index.uts
index 38c4714579bfb0079391a1eb0bba981fe03549c3..7bf68743f72f080a545c56806775c928d46e774d 100644
--- a/store/index.uts
+++ b/store/index.uts
@@ -1,16 +1,22 @@
export type State = {
- colorIndex: number,
- currentColor: string
+ colorIndex: number,
+ currentColor: string,
+ lifeCycleNum: number
}
const colorList: string[] = ['#FF0000', '#00FF00', '#0000FF']
export const state = reactive({
- colorIndex: 0,
- currentColor: colorList[0]
+ colorIndex: 0,
+ currentColor: colorList[0],
+ lifeCycleNum: 0
} as State)
export const setColorIndex = (index: number) => {
state.colorIndex = index
state.currentColor = colorList[index]
}
+
+export const setLifeCycleNum = (num: number) => {
+ state.lifeCycleNum = num
+}