Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
97155cf5
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
349
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
>
export
default
{
onLaunch
:
function
()
{
console
.
log
(
'
App Launch
'
)
<
script
lang=
"ts"
>
import
{
state
,
setLifeCycleNum
}
from
'
./store/index.uts
'
export
default
{
onLaunch
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
+
1000
)
console
.
log
(
'
App Launch
'
)
const
performance
:
Performance
=
uni
.
getPerformance
()
const
observer
:
PerformanceObserver
=
performance
.
createObserver
((
entryList
:
PerformanceObserverEntryList
)
=>
{
console
.
log
(
"
observer:entryList.getEntries()
"
)
console
.
log
(
entryList
.
getEntries
())
})
observer
.
observe
({
entryTypes
:
[
'
render
'
,
'
navigation
'
]
}
as
PerformanceObserverOptions
)
},
onShow
:
function
()
{
console
.
log
(
'
App Show
'
)
},
onHide
:
function
()
{
console
.
log
(
'
App Hide
'
)
}
}
const
performance
:
Performance
=
uni
.
getPerformance
()
const
observer
:
PerformanceObserver
=
performance
.
createObserver
((
entryList
:
PerformanceObserverEntryList
)
=>
{
console
.
log
(
"
observer:entryList.getEntries()
"
)
console
.
log
(
entryList
.
getEntries
())
})
observer
.
observe
({
entryTypes
:
[
'
render
'
,
'
navigation
'
]
}
as
PerformanceObserverOptions
)
},
onShow
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
+
100
)
console
.
log
(
'
App Show
'
)
},
onHide
:
function
()
{
setLifeCycleNum
(
state
.
lifeCycleNum
-
100
)
console
.
log
(
'
App Hide
'
)
},
onLastPageBackPress
():
boolean
|
null
{
setLifeCycleNum
(
state
.
lifeCycleNum
-
1000
)
console
.
log
(
'
App onLastPageBackPress
'
)
return
null
},
}
</
script
>
<
style
>
/* @font-face {
/* @font-face {
font-family: uniicons;
font-weight: normal;
font-style: normal;
src: url('./static/fonts/uni.ttf') format('truetype');
} */
.page
{
padding
:
15px
;
}
.page
{
padding
:
15px
;
}
.uni-panel
{
margin-bottom
:
12px
;
}
.uni-panel
{
margin-bottom
:
12px
;
}
.uni-panel-h
{
background-color
:
#ffffff
;
flex-direction
:
row
;
align-items
:
center
;
padding
:
12px
;
}
.uni-panel-h
{
background-color
:
#ffffff
;
flex-direction
:
row
;
align-items
:
center
;
padding
:
12px
;
}
.uni-panel-h-on
{
background-color
:
#f0f0f0
;
}
.uni-panel-h-on
{
background-color
:
#f0f0f0
;
}
.uni-panel-text
{
color
:
#000000
;
font-size
:
14px
;
font-weight
:
normal
;
}
.uni-panel-text
{
color
:
#000000
;
font-size
:
14px
;
font-weight
:
normal
;
}
.uni-panel-icon
{}
.uni-panel-icon
{}
.uni-panel-icon-on
{
transform
:
rotate
(
180deg
);
}
.uni-panel-icon-on
{
transform
:
rotate
(
180deg
);
}
.uni-navigate-item
{
flex-direction
:
row
;
align-items
:
center
;
background-color
:
#FFFFFF
;
border-top-style
:
solid
;
border-top-color
:
#f0f0f0
;
border-top-width
:
1px
;
padding
:
12px
;
justify-content
:
space-between
;
}
.uni-navigate-item
{
flex-direction
:
row
;
align-items
:
center
;
background-color
:
#FFFFFF
;
border-top-style
:
solid
;
border-top-color
:
#f0f0f0
;
border-top-width
:
1px
;
padding
:
12px
;
justify-content
:
space-between
;
}
.uni-navigate-item
:active
{
background-color
:
#f8f8f8
;
}
.uni-navigate-item
:active
{
background-color
:
#f8f8f8
;
}
.uni-navigate-text
{
color
:
#000000
;
font-size
:
12px
;
opacity
:
0.8
;
}
.uni-navigate-text
{
color
:
#000000
;
font-size
:
12px
;
opacity
:
0.8
;
}
.uni-navigate-icon
{
margin-left
:
15px
;
color
:
#999999
;
font-size
:
14px
;
font-weight
:
normal
;
}
.uni-navigate-icon
{
margin-left
:
15px
;
color
:
#999999
;
font-size
:
14px
;
font-weight
:
normal
;
}
.split-title
{
margin
:
20px
0
5px
;
padding
:
5px
0
;
border-bottom
:
1px
solid
#dfdfdf
;
}
.split-title
{
margin
:
20px
0
5px
;
padding
:
5px
0
;
border-bottom
:
1px
solid
#dfdfdf
;
}
</
style
>
\ No newline at end of file
pages.json
浏览文件 @
97155cf5
...
...
@@ -52,6 +52,11 @@
"style"
:
{
"navigationBarTitleText"
:
"v-slot"
}
},{
"path"
:
"pages/page-lifecycle/page-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"page-lifecycle"
}
}
],
"globalStyle"
:
{
...
...
pages/index.uvue
浏览文件 @
97155cf5
...
...
@@ -16,6 +16,7 @@
</template>
<script lang="ts">
import { state } from '../store/index.uts'
const STORAGE_KEY_PREFIX = 'INDEX-STATUS'
let storageData : Array<string> = []
...
...
@@ -35,16 +36,7 @@
name: '生命周期',
open: false,
pages: [
'beforeCreate',
'created',
'beforeMount',
'mounted',
// 'beforeUpdate',
// 'updated',
'beforeUnmount',
'unmounted',
'activated',
'deactivated',
'page-lifecycle',
]
},
{
...
...
@@ -157,7 +149,10 @@
uni.navigateTo({
url: `/pages/${e}/${e}`
})
}
},
getLifeCycleNum(): number {
return state.lifeCycleNum
},
}
}
</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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录