Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
97155cf5
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
350
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
97155cf5
编写于
6月 30, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: page lifecycle
上级
b496f0a3
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
184 addition
and
83 deletion
+184
-83
App.vue
App.vue
+81
-72
pages.json
pages.json
+5
-0
pages/index.uvue
pages/index.uvue
+6
-11
pages/page-lifecycle/page-lifecycle.test.js
pages/page-lifecycle/page-lifecycle.test.js
+41
-0
pages/page-lifecycle/page-lifecycle.uvue
pages/page-lifecycle/page-lifecycle.uvue
+41
-0
store/index.uts
store/index.uts
+10
-0
未找到文件。
App.vue
浏览文件 @
97155cf5
<
script
>
<
script
lang=
"ts"
>
export
default
{
import
{
state
,
setLifeCycleNum
}
from
'
./store/index.uts
'
onLaunch
:
function
()
{
export
default
{
onLaunch
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
+
1000
)
console
.
log
(
'
App Launch
'
)
console
.
log
(
'
App Launch
'
)
const
performance
:
Performance
=
uni
.
getPerformance
()
const
performance
:
Performance
=
uni
.
getPerformance
()
...
@@ -10,55 +12,62 @@
...
@@ -10,55 +12,62 @@
})
})
observer
.
observe
({
entryTypes
:
[
'
render
'
,
'
navigation
'
]
}
as
PerformanceObserverOptions
)
observer
.
observe
({
entryTypes
:
[
'
render
'
,
'
navigation
'
]
}
as
PerformanceObserverOptions
)
},
},
onShow
:
function
()
{
onShow
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
+
100
)
console
.
log
(
'
App Show
'
)
console
.
log
(
'
App Show
'
)
},
},
onHide
:
function
()
{
onHide
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
-
100
)
console
.
log
(
'
App Hide
'
)
console
.
log
(
'
App Hide
'
)
}
},
}
onLastPageBackPress
():
boolean
|
null
{
setLifeCycleNum
(
state
.
lifeCycleNum
-
1000
)
console
.
log
(
'
App onLastPageBackPress
'
)
return
null
},
}
</
script
>
</
script
>
<
style
>
<
style
>
/* @font-face {
/* @font-face {
font-family: uniicons;
font-family: uniicons;
font-weight: normal;
font-weight: normal;
font-style: normal;
font-style: normal;
src: url('./static/fonts/uni.ttf') format('truetype');
src: url('./static/fonts/uni.ttf') format('truetype');
} */
} */
.page
{
.page
{
padding
:
15px
;
padding
:
15px
;
}
}
.uni-panel
{
.uni-panel
{
margin-bottom
:
12px
;
margin-bottom
:
12px
;
}
}
.uni-panel-h
{
.uni-panel-h
{
background-color
:
#ffffff
;
background-color
:
#ffffff
;
flex-direction
:
row
;
flex-direction
:
row
;
align-items
:
center
;
align-items
:
center
;
padding
:
12px
;
padding
:
12px
;
}
}
.uni-panel-h-on
{
.uni-panel-h-on
{
background-color
:
#f0f0f0
;
background-color
:
#f0f0f0
;
}
}
.uni-panel-text
{
.uni-panel-text
{
color
:
#000000
;
color
:
#000000
;
font-size
:
14px
;
font-size
:
14px
;
font-weight
:
normal
;
font-weight
:
normal
;
}
}
.uni-panel-icon
{}
.uni-panel-icon
{}
.uni-panel-icon-on
{
.uni-panel-icon-on
{
transform
:
rotate
(
180deg
);
transform
:
rotate
(
180deg
);
}
}
.uni-navigate-item
{
.uni-navigate-item
{
flex-direction
:
row
;
flex-direction
:
row
;
align-items
:
center
;
align-items
:
center
;
background-color
:
#FFFFFF
;
background-color
:
#FFFFFF
;
...
@@ -67,28 +76,28 @@
...
@@ -67,28 +76,28 @@
border-top-width
:
1px
;
border-top-width
:
1px
;
padding
:
12px
;
padding
:
12px
;
justify-content
:
space-between
;
justify-content
:
space-between
;
}
}
.uni-navigate-item
:active
{
.uni-navigate-item
:active
{
background-color
:
#f8f8f8
;
background-color
:
#f8f8f8
;
}
}
.uni-navigate-text
{
.uni-navigate-text
{
color
:
#000000
;
color
:
#000000
;
font-size
:
12px
;
font-size
:
12px
;
opacity
:
0.8
;
opacity
:
0.8
;
}
}
.uni-navigate-icon
{
.uni-navigate-icon
{
margin-left
:
15px
;
margin-left
:
15px
;
color
:
#999999
;
color
:
#999999
;
font-size
:
14px
;
font-size
:
14px
;
font-weight
:
normal
;
font-weight
:
normal
;
}
}
.split-title
{
.split-title
{
margin
:
20px
0
5px
;
margin
:
20px
0
5px
;
padding
:
5px
0
;
padding
:
5px
0
;
border-bottom
:
1px
solid
#dfdfdf
;
border-bottom
:
1px
solid
#dfdfdf
;
}
}
</
style
>
</
style
>
\ No newline at end of file
pages.json
浏览文件 @
97155cf5
...
@@ -52,6 +52,11 @@
...
@@ -52,6 +52,11 @@
"style"
:
{
"style"
:
{
"navigationBarTitleText"
:
"v-slot"
"navigationBarTitleText"
:
"v-slot"
}
}
},{
"path"
:
"pages/page-lifecycle/page-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"page-lifecycle"
}
}
}
],
],
"globalStyle"
:
{
"globalStyle"
:
{
...
...
pages/index.uvue
浏览文件 @
97155cf5
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
</template>
</template>
<script lang="ts">
<script lang="ts">
import { state } from '../store/index.uts'
const STORAGE_KEY_PREFIX = 'INDEX-STATUS'
const STORAGE_KEY_PREFIX = 'INDEX-STATUS'
let storageData : Array<string> = []
let storageData : Array<string> = []
...
@@ -35,16 +36,7 @@
...
@@ -35,16 +36,7 @@
name: '生命周期',
name: '生命周期',
open: false,
open: false,
pages: [
pages: [
'beforeCreate',
'page-lifecycle',
'created',
'beforeMount',
'mounted',
// 'beforeUpdate',
// 'updated',
'beforeUnmount',
'unmounted',
'activated',
'deactivated',
]
]
},
},
{
{
...
@@ -157,7 +149,10 @@
...
@@ -157,7 +149,10 @@
uni.navigateTo({
uni.navigateTo({
url: `/pages/${e}/${e}`
url: `/pages/${e}/${e}`
})
})
}
},
getLifeCycleNum(): number {
return state.lifeCycleNum
},
}
}
}
}
</script>
</script>
...
...
pages/page-lifecycle/page-lifecycle.test.js
0 → 100644
浏览文件 @
97155cf5
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
pages/page-lifecycle/page-lifecycle.uvue
0 → 100644
浏览文件 @
97155cf5
<template>
<view class="page">
<text>page lifecycle</text>
</view>
</template>
<script lang="ts">
import { state, setLifeCycleNum } from '../../store/index.uts'
export default {
onLoad() {
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('Page onLoad')
},
onShow() {
setLifeCycleNum(state.lifeCycleNum + 10)
console.log('Page onShow')
},
onReady() {
setLifeCycleNum(state.lifeCycleNum + 10)
console.log('Page onReady')
},
onHide() {
setLifeCycleNum(state.lifeCycleNum - 10)
console.log('Page onHide')
},
onUnload() {
setLifeCycleNum(state.lifeCycleNum - 100)
console.log('Page onUnload')
},
onBackPress(options: Map<string, string>) : boolean | null {
setLifeCycleNum(state.lifeCycleNum - 10)
console.log('Page onBackPress',options)
return null
},
methods: {
getLifeCycleNum() : number {
return state.lifeCycleNum
}
},
}
</script>
\ No newline at end of file
store/index.uts
0 → 100644
浏览文件 @
97155cf5
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录