Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
318c2ef8
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
376
Star
3
Fork
8
代码
文件
提交
分支
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看板
提交
318c2ef8
编写于
5月 08, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(render function): mergeProps
上级
f17af7cf
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1264 addition
and
1107 deletion
+1264
-1107
pages.json
pages.json
+12
-0
pages/index/index.uvue
pages/index/index.uvue
+1123
-1107
pages/render-function/mergeProps/mergeProps-composition.uvue
pages/render-function/mergeProps/mergeProps-composition.uvue
+46
-0
pages/render-function/mergeProps/mergeProps-options.uvue
pages/render-function/mergeProps/mergeProps-options.uvue
+53
-0
pages/render-function/mergeProps/mergeProps.test.js
pages/render-function/mergeProps/mergeProps.test.js
+30
-0
未找到文件。
pages.json
浏览文件 @
318c2ef8
...
@@ -716,6 +716,18 @@
...
@@ -716,6 +716,18 @@
"navigationBarTitleText"
:
"render function"
"navigationBarTitleText"
:
"render function"
}
}
},
},
{
"path"
:
"pages/render-function/mergeProps/mergeProps-options"
,
"style"
:
{
"navigationBarTitleText"
:
"mergeProps 选项式 API"
}
},
{
"path"
:
"pages/render-function/mergeProps/mergeProps-composition"
,
"style"
:
{
"navigationBarTitleText"
:
"mergeProps 组合式 API"
}
},
{
{
"path"
:
"pages/examples/unrecognized-component/unrecognized-component"
,
"path"
:
"pages/examples/unrecognized-component/unrecognized-component"
,
"style"
:
{
"style"
:
{
...
...
pages/index/index.uvue
浏览文件 @
318c2ef8
此差异已折叠。
点击以展开。
pages/render-function/mergeProps/mergeProps-composition.uvue
0 → 100644
浏览文件 @
318c2ef8
<template>
<view class="page">
<view class="mb-10 flex flex-row justify-between">
<text>merged class</text>
<text id="merged-class">{{mergedProps['class']}}</text>
</view>
<button class="mb-10" id="trigger-merged-click" @click="triggerMergedClick">trigger merged onClick</button>
<view>
<text class="mb-10">prop function result list</text>
<text class="click-res" v-for="(item, index) in propFnResList" :key="index">{{item}}</text>
</view>
</view>
</template>
<script setup lang="uts">
// TODO: 确认 android 与 web & ios 差异
// #ifndef APP-ANDROID
import { mergeProps } from 'vue'
// #endif
type PropFn = () => string
// #ifdef APP-ANDROID
const propA = new Map<string, any | null>([['class', 'foo'], ['onClick', () : string => 'propA click res']])
const propB = new Map<string, any | null>([['class', { bar: true }], ['onClick', () : string => 'propB click res']])
const mergedProps = ref(new Map<string, any | null>())
// #endif
// #ifndef APP-ANDROID
const propA = {
class: 'foo',
onClick: () : string => 'propA click res'
}
const propB = {
class: { bar: true },
onClick: () : string => 'propB click res'
}
const mergedProps = ref({})
// #endif
const propFnResList = ref<string[]>([])
mergedProps.value = mergeProps(propA, propB)
const triggerMergedClick = () => {
(mergedProps.value['onClick'] as PropFn[]).forEach(fn => { propFnResList.value.push(fn()) })
}
</script>
\ No newline at end of file
pages/render-function/mergeProps/mergeProps-options.uvue
0 → 100644
浏览文件 @
318c2ef8
<template>
<view class="page">
<view class="mb-10 flex flex-row justify-between">
<text>merged class</text>
<text id="merged-class">{{mergedProps['class']}}</text>
</view>
<button class="mb-10" id="trigger-merged-click" @click="triggerMergedClick">trigger merged onClick</button>
<view>
<text class="mb-10">prop function result list</text>
<text class="click-res" v-for="(item, index) in propFnResList" :key="index">{{item}}</text>
</view>
</view>
</template>
<script lang="uts">
// TODO: 确认 android 与 web & ios 差异
// #ifndef APP-ANDROID
import { mergeProps } from 'vue'
// #endif
type PropFn = () => string
export default {
data() {
return {
// #ifdef APP-ANDROID
propA: new Map<string, any | null>([['class', 'foo'], ['onClick', () : string => 'propA click res']]),
propB: new Map<string, any | null>([['class', { bar: true }], ['onClick', () : string => 'propB click res']]),
mergedProps: new Map<string, any | null>(),
// #endif
// #ifndef APP-ANDROID
propA: {
class: 'foo',
onClick: () : string => 'propA click res'
},
propB: {
class: { bar: true },
onClick: () : string => 'propB click res'
},
mergedProps: {},
// #endif
propFnResList: [] as string[],
}
},
onLoad() {
this.mergedProps = mergeProps(this.propA, this.propB)
},
methods: {
triggerMergedClick() {
(this.mergedProps['onClick'] as PropFn[]).forEach(fn => { this.propFnResList.push(fn()) })
}
}
}
</script>
\ No newline at end of file
pages/render-function/mergeProps/mergeProps.test.js
0 → 100644
浏览文件 @
318c2ef8
const
OPTIONS_PAGE_PATH
=
'
/pages/render-function/mergeProps/mergeProps-options
'
const
COMPOSITION_PAGE_PATH
=
'
/pages/render-function/mergeProps/mergeProps-composition
'
describe
(
'
mergeProps
'
,
()
=>
{
let
page
=
null
const
test
=
async
(
pagePath
)
=>
{
page
=
await
program
.
reLaunch
(
pagePath
)
await
page
.
waitFor
(
'
view
'
)
const
mergedClass
=
await
page
.
$
(
'
#merged-class
'
)
expect
(
await
mergedClass
.
text
()).
toBe
(
'
foo bar
'
)
const
triggerMergedClickBtn
=
await
page
.
$
(
'
#trigger-merged-click
'
)
await
triggerMergedClickBtn
.
tap
()
const
clickResList
=
await
page
.
$$
(
'
.click-res
'
)
expect
(
clickResList
.
length
).
toBe
(
2
)
expect
(
await
clickResList
[
0
].
text
()).
toBe
(
'
propA click res
'
)
expect
(
await
clickResList
[
1
].
text
()).
toBe
(
'
propB click res
'
)
}
it
(
'
mergeProps options API
'
,
async
()
=>
{
await
test
(
OPTIONS_PAGE_PATH
)
})
it
(
'
mergeProps composition API
'
,
async
()
=>
{
await
test
(
COMPOSITION_PAGE_PATH
)
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录