Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
4b21f575
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
348
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看板
提交
4b21f575
编写于
7月 12, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 补充 onBackPress 示例及测试
上级
6971e295
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
159 addition
and
4 deletion
+159
-4
pages.json
pages.json
+24
-0
pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue
...cle/page/onBackPress/on-back-press-child-composition.uvue
+12
-0
pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue
...fecycle/page/onBackPress/on-back-press-child-options.uvue
+14
-0
pages/lifecycle/page/onBackPress/on-back-press-composition.uvue
...lifecycle/page/onBackPress/on-back-press-composition.uvue
+28
-0
pages/lifecycle/page/onBackPress/on-back-press-options.uvue
pages/lifecycle/page/onBackPress/on-back-press-options.uvue
+30
-0
pages/lifecycle/page/onBackPress/on-back-press.test.js
pages/lifecycle/page/onBackPress/on-back-press.test.js
+34
-0
pages/lifecycle/page/page-composition.uvue
pages/lifecycle/page/page-composition.uvue
+11
-4
pages/lifecycle/page/page-options.uvue
pages/lifecycle/page/page-options.uvue
+6
-0
未找到文件。
pages.json
浏览文件 @
4b21f575
...
...
@@ -624,6 +624,30 @@
"enablePullDownRefresh"
:
true
}
},
{
"path"
:
"pages/lifecycle/page/onBackPress/on-back-press-options"
,
"style"
:
{
"navigationBarTitleText"
:
"onBackPress 选项式 API"
}
},
{
"path"
:
"pages/lifecycle/page/onBackPress/on-back-press-child-options"
,
"style"
:
{
"navigationBarTitleText"
:
"onBackPress 选项式 API"
}
},
{
"path"
:
"pages/lifecycle/page/onBackPress/on-back-press-composition"
,
"style"
:
{
"navigationBarTitleText"
:
"onBackPress 组合式 API"
}
},
{
"path"
:
"pages/lifecycle/page/onBackPress/on-back-press-child-composition"
,
"style"
:
{
"navigationBarTitleText"
:
"onBackPress 组合式 API"
}
},
{
"path"
:
"pages/lifecycle/component/component-options"
,
"style"
:
{
...
...
pages/lifecycle/page/onBackPress/on-back-press-child-composition.uvue
0 → 100644
浏览文件 @
4b21f575
<template>
<view class="page container">
<text>测试 onBackPress 生命周期返回 false</text>
</view>
</template>
<script lang='uts' setup>
onBackPress((options: OnBackPressOptions): boolean | null => {
console.log('onBackPress', options)
return false
})
</script>
\ No newline at end of file
pages/lifecycle/page/onBackPress/on-back-press-child-options.uvue
0 → 100644
浏览文件 @
4b21f575
<template>
<view class="page container">
<text>测试 onBackPress 生命周期返回 false</text>
</view>
</template>
<script lang='uts'>
export default {
onBackPress(options: OnBackPressOptions): boolean | null {
console.log('onBackPress', options)
return false
}
}
</script>
\ No newline at end of file
pages/lifecycle/page/onBackPress/on-back-press-composition.uvue
0 → 100644
浏览文件 @
4b21f575
<template>
<view class="page container">
<text>测试 onBackPress 生命周期返回 true</text>
<button class="mt-10" @click="goChildPage">
跳转子页,测试返回值为 false
</button>
</view>
</template>
<script lang="uts" setup>
const backPressOptions = reactive({
from: 'backbutton'
} as OnBackPressOptions)
onBackPress((options : OnBackPressOptions) : boolean | null => {
console.log('onBackPress', options)
backPressOptions.from = options.from
return true
})
const goChildPage = () => {
uni.navigateTo({ url: '/pages/lifecycle/page/onBackPress/on-back-press-child-composition' })
}
defineExpose({
goChildPage,
backPressOptions
})
</script>
\ No newline at end of file
pages/lifecycle/page/onBackPress/on-back-press-options.uvue
0 → 100644
浏览文件 @
4b21f575
<template>
<view class="page container">
<text>测试 onBackPress 生命周期返回 true</text>
<button class='mt-10' @click="goChildPage">跳转子页,测试返回值为 false</button>
</view>
</template>
<script lang='uts'>
export default {
data() {
return {
backPressOptions: {
from: 'backbutton'
} as OnBackPressOptions
}
},
onBackPress(options: OnBackPressOptions): boolean | null {
console.log('onBackPress', options)
this.backPressOptions = options
return true
},
methods: {
goChildPage() {
uni.navigateTo({
url: '/pages/lifecycle/page/onBackPress/on-back-press-child-options'
})
}
}
}
</script>
\ No newline at end of file
pages/lifecycle/page/onBackPress/on-back-press.test.js
0 → 100644
浏览文件 @
4b21f575
jest
.
setTimeout
(
30000
)
const
OPTIONS_PAGE_PATH
=
'
/pages/lifecycle/page/onBackPress/on-back-press-options
'
const
OPTIONS_CHILD_PAGE_PATH
=
'
/pages/lifecycle/page/onBackPress/on-back-press-child-options
'
const
COMPOSITION_PAGE_PATH
=
'
/pages/lifecycle/page/onBackPress/on-back-press-composition
'
const
COMPOSITION_CHILD_PAGE_PATH
=
'
/pages/lifecycle/page/onBackPress/on-back-press-child-composition
'
describe
(
'
onBackPress 返回值
'
,
()
=>
{
const
test
=
async
(
pagePath
,
childPagePath
)
=>
{
const
page
=
await
program
.
navigateTo
(
pagePath
)
await
page
.
waitFor
(
'
view
'
)
expect
(
page
.
path
).
toBe
(
pagePath
.
substring
(
1
))
await
page
.
callMethod
(
'
goChildPage
'
)
await
page
.
waitFor
(
800
)
const
childPage
=
await
program
.
currentPage
()
await
childPage
.
waitFor
(
'
view
'
)
expect
(
childPage
.
path
).
toBe
(
childPagePath
.
substring
(
1
))
await
program
.
navigateBack
()
let
currentPage
=
await
program
.
currentPage
()
expect
(
currentPage
.
path
).
toBe
(
pagePath
.
substring
(
1
))
await
program
.
navigateBack
()
currentPage
=
await
program
.
currentPage
()
expect
(
currentPage
.
path
).
toBe
(
pagePath
.
substring
(
1
))
const
currentPageData
=
await
currentPage
.
data
(
'
backPressOptions
'
)
expect
(
currentPageData
.
from
).
toBe
(
'
navigateBack
'
)
}
it
(
'
onBackPress options API
'
,
async
()
=>
{
await
test
(
OPTIONS_PAGE_PATH
,
OPTIONS_CHILD_PAGE_PATH
)
})
it
(
'
onBackPress composition API
'
,
async
()
=>
{
await
test
(
COMPOSITION_PAGE_PATH
,
COMPOSITION_CHILD_PAGE_PATH
)
})
});
\ No newline at end of file
pages/lifecycle/page/page-composition.uvue
浏览文件 @
4b21f575
...
...
@@ -35,14 +35,17 @@
<view class="flex flex-row justify-between mt-10">
<text>onResize 触发:</text>
<text>{{ isOnResizeTriggered }}</text>
</view>
<view class="flex flex-row justify-between mt-10">
<MonitorPageLifecycleComposition />
</view>
<view class="flex flex-row justify-between mt-10">
<MonitorPageLifecycleComposition />
</view>
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button class="mt-10" @click="pullDownRefresh">
trigger pullDownRefresh
</button>
<button class="mt-10" @click="goOnBackPress">
跳转 onBackPress 示例
</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
...
...
@@ -50,7 +53,7 @@
</template>
<script setup lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
import MonitorPageLifecycleComposition from './monitor-page-lifecycle-composition.uvue'
const isOnloadTriggered = ref(false)
...
...
@@ -151,6 +154,10 @@ const scrollToBottom = () => {
})
}
const goOnBackPress = () => {
uni.navigateTo({url: '/pages/lifecycle/page/onBackPress/on-back-press-composition'})
}
defineExpose({
dataInfo,
pageGetLifeCycleNum,
...
...
pages/lifecycle/page/page-options.uvue
浏览文件 @
4b21f575
...
...
@@ -40,6 +40,9 @@
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button class="mt-10" @click="pullDownRefresh">
trigger pullDownRefresh
</button>
<button class="mt-10" @click="goOnBackPress">
跳转 onBackPress 示例
</button>
</view>
<!-- #ifdef APP -->
...
...
@@ -150,6 +153,9 @@ export default {
scrollTop: 2000,
})
},
goOnBackPress() {
uni.navigateTo({url: '/pages/lifecycle/page/onBackPress/on-back-press-options'})
}
},
}
</script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录