Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
5d624eac
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
347
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看板
提交
5d624eac
编写于
6月 30, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: lifecycle
上级
d4a5f1ec
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
153 addition
and
12 deletion
+153
-12
components/Lifecycle.uvue
components/Lifecycle.uvue
+54
-0
pages.json
pages.json
+8
-1
pages/component-lifecycle/component-lifecycle.test.js
pages/component-lifecycle/component-lifecycle.test.js
+42
-0
pages/component-lifecycle/component-lifecycle.uvue
pages/component-lifecycle/component-lifecycle.uvue
+19
-0
pages/index.uvue
pages/index.uvue
+7
-2
pages/page-lifecycle/page-lifecycle.test.js
pages/page-lifecycle/page-lifecycle.test.js
+23
-9
未找到文件。
components/Lifecycle.uvue
0 → 100644
浏览文件 @
5d624eac
<template>
<view>
<text>{{title}}</text>
</view>
</template>
<script lang="ts">
import { state, setLifeCycleNum } from '../store/index.uts'
export default {
name: 'ComponentLifecycle',
data(){
return {
title: 'component for lifecycle test'
}
},
beforeCreate() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test beforeCreate')
},
created() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test created')
},
beforeMount() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test beforeMount')
},
mounted() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test mounted')
},
beforeUpdate() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test beforeUpdate')
},
updated() {
setLifeCycleNum(state.lifeCycleNum + 1)
console.log('component for lifecycle test updated')
},
beforeUnmount() {
setLifeCycleNum(state.lifeCycleNum - 1)
console.log('component for lifecycle test beforeUnmount')
},
unmounted() {
setLifeCycleNum(state.lifeCycleNum - 1)
console.log('component for lifecycle test unmounted')
},
methods: {
getLifeCycleNum(): number {
return state.lifeCycleNum
}
},
}
</script>
pages.json
浏览文件 @
5d624eac
...
...
@@ -52,12 +52,19 @@
"style"
:
{
"navigationBarTitleText"
:
"v-slot"
}
},{
},
{
"path"
:
"pages/page-lifecycle/page-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"page-lifecycle"
}
},
{
"path"
:
"pages/component-lifecycle/component-lifecycle"
,
"style"
:
{
"navigationBarTitleText"
:
"component-lifecycle"
}
},
{
"path"
:
"pages/component-instance/data/data"
,
"style"
:
{
...
...
pages/component-lifecycle/component-lifecycle.test.js
0 → 100644
浏览文件 @
5d624eac
const
PAGE_PATH
=
'
/pages/component-lifecycle/component-lifecycle
'
const
HOME_PATH
=
'
/pages/index
'
describe
(
'
component-lifecycle
'
,
()
=>
{
let
page
let
lifeCycleNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_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
.
navigateTo
(
PAGE_PATH
)
await
page
.
waitFor
(
1000
)
})
it
(
'
beforeCreate created beforeMount mounted
'
,
async
()
=>
{
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
4
)
})
it
(
'
beforeUpdate updated
'
,
async
()
=>
{
const
component
=
await
page
.
$
(
'
.component-lifecycle
'
)
await
component
.
setData
({
title
:
'
component for lifecycle test new title
'
})
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
6
)
})
it
(
'
beforeUnmount unmounted
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
4
)
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
})
pages/component-lifecycle/component-lifecycle.uvue
0 → 100644
浏览文件 @
5d624eac
<template>
<view class="page">
<text>component lifecycle</text>
<component-lifecycle class="component-lifecycle" />
</view>
</template>
<script lang="ts">
import ComponentLifecycle from '../../components/Lifecycle.uvue'
import { state } from '../../store/index.uts'
export default {
components: { ComponentLifecycle },
methods: {
getLifeCycleNum(): number {
return state.lifeCycleNum
}
},
}
</script>
pages/index.uvue
浏览文件 @
5d624eac
...
...
@@ -16,7 +16,7 @@
</template>
<script lang="ts">
import { state } from '../store/index.uts'
import { s
etLifeCycleNum, s
tate } from '../store/index.uts'
const STORAGE_KEY_PREFIX = 'INDEX-STATUS'
let storageData : Array<string> = []
...
...
@@ -51,7 +51,8 @@
name: '生命周期',
open: false,
pages: [
'page-lifecycle'
'page-lifecycle',
'component-lifecycle'
].map(createPageItem())
},
{
...
...
@@ -165,6 +166,10 @@
url: e.path
})
},
setLifeCycleNum(num: number){
console.warn('index setLifeCycleNum', num)
setLifeCycleNum(num)
},
getLifeCycleNum(): number {
return state.lifeCycleNum
},
...
...
pages/page-lifecycle/page-lifecycle.test.js
浏览文件 @
5d624eac
...
...
@@ -5,37 +5,51 @@ describe('page-lifecycle', () => {
let
page
let
lifeCycleNum
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
page
=
await
program
.
reLaunch
(
HOME_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
(
12
2
0
)
expect
(
lifeCycleNum
).
toBe
(
120
)
})
it
(
'
onHide
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
HOME_PATH
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1
2
10
)
expect
(
lifeCycleNum
).
toBe
(
110
)
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
12
2
0
)
expect
(
lifeCycleNum
).
toBe
(
120
)
})
it
(
'
onUnload
'
,
async
()
=>
{
page
=
await
program
.
redirectTo
(
HOME_PATH
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
11
20
)
expect
(
lifeCycleNum
).
toBe
(
20
)
})
it
(
'
onBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
PAGE_PATH
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
1
2
40
)
expect
(
lifeCycleNum
).
toBe
(
140
)
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
11
30
)
expect
(
lifeCycleNum
).
toBe
(
30
)
})
it
(
'
onLastPageBackPress
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
130
)
expect
(
lifeCycleNum
).
toBe
(
-
970
)
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
})
\ No newline at end of file
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录