Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
b043eb7e
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看板
提交
b043eb7e
编写于
7月 30, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v-slot): 补充 v-for 动态插槽名示例
上级
9022b1b2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
114 addition
and
31 deletion
+114
-31
pages/directive/v-slot/Foo-composition.uvue
pages/directive/v-slot/Foo-composition.uvue
+8
-0
pages/directive/v-slot/Foo-options.uvue
pages/directive/v-slot/Foo-options.uvue
+8
-0
pages/directive/v-slot/v-slot-composition.uvue
pages/directive/v-slot/v-slot-composition.uvue
+55
-28
pages/directive/v-slot/v-slot-options.uvue
pages/directive/v-slot/v-slot-options.uvue
+31
-1
pages/directive/v-slot/v-slot.test.js
pages/directive/v-slot/v-slot.test.js
+12
-2
未找到文件。
pages/directive/v-slot/Foo-composition.uvue
浏览文件 @
b043eb7e
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
<view>
<view>
<slot name="header" :msg="msg"></slot>
<slot name="header" :msg="msg"></slot>
<slot :num="num"></slot>
<slot :num="num"></slot>
<slot name="num1" :num="num"></slot>
<slot name="num2" :num="num"></slot>
<slot name="msgTrue" :msg="msg"></slot>
<slot name="msgFalse" :msg="msg"></slot>
<slot name="footer" :arr="arr"></slot>
<slot name="footer" :arr="arr"></slot>
</view>
</view>
</template>
</template>
...
@@ -14,6 +18,10 @@
...
@@ -14,6 +18,10 @@
defineSlots<{
defineSlots<{
header(props : { msg : string }) : any,
header(props : { msg : string }) : any,
default(props : { num : number }) : any,
default(props : { num : number }) : any,
num1(props : { num : number }) : any,
num2(props : { num : number }) : any,
msgTrue(props : { msg : string }) : any,
msgFalse(props : { msg : string }) : any,
footer(props : { arr : string[] }) : any
footer(props : { arr : string[] }) : any
}>()
}>()
</script>
</script>
pages/directive/v-slot/Foo-options.uvue
浏览文件 @
b043eb7e
...
@@ -2,6 +2,10 @@
...
@@ -2,6 +2,10 @@
<view>
<view>
<slot name="header" :msg="msg"></slot>
<slot name="header" :msg="msg"></slot>
<slot :num="num"></slot>
<slot :num="num"></slot>
<slot name="num1" :num="num"></slot>
<slot name="num2" :num="num"></slot>
<slot name="msgTrue" :msg="msg"></slot>
<slot name="msgFalse" :msg="msg"></slot>
<slot name="footer" :arr="arr"></slot>
<slot name="footer" :arr="arr"></slot>
</view>
</view>
</template>
</template>
...
@@ -11,6 +15,10 @@
...
@@ -11,6 +15,10 @@
slots: Object as SlotsType<{
slots: Object as SlotsType<{
header: { msg: string }
header: { msg: string }
default: { num: number }
default: { num: number }
num1: { num: number }
num2: { num: number }
msgTrue: { msg: string }
msgFalse: { msg: string }
footer: { arr: string[] }
footer: { arr: string[] }
}>,
}>,
data(){
data(){
...
...
pages/directive/v-slot/v-slot-composition.uvue
浏览文件 @
b043eb7e
<template>
<template>
<view class="page">
<view class="page">
<Foo>
<Foo>
<template #header="{ msg }">
<template #header="{ msg }">
<view class="mb-10 flex justify-between flex-row">
<view class="mb-10 flex justify-between flex-row">
<text>header slot msg:</text>
<text>header slot msg:</text>
<text id="slot-header">{{ msg }}</text>
<text id="slot-header">{{ msg }}</text>
</view>
</view>
</template>
</template>
<template #default="{ num }">
<template #default="{ num }">
<view class="mb-10 flex justify-between flex-row">
<view class="mb-10 flex justify-between flex-row">
<text>default slot num:</text>
<text>default slot num:</text>
<text id="slot-default">{{ num }}</text>
<text id="slot-default">{{ num }}</text>
</view>
</view>
</template>
</template>
<template #footer="{ arr }">
<template v-for="item in 2" #[`num${item}`]="{ num }">
<view class="mb-10 flex justify-between flex-row">
<view class="mb-10 flex justify-between flex-row">
<text>footer slot arr:</text>
<text>num{{ item }} slot:</text>
<text id="slot-footer">{{ JSON.stringify(arr) }}</text>
<text :id="`slot-num${item}`">{{ num }}</text>
</view>
</view>
</template>
</template>
</Foo>
<template v-if="msgTrue['isShow']" #[msgTrue['name']]="{ msg }">
</view>
<view class="mb-10 flex justify-between flex-row">
</template>
<text>{{ msgTrue['name'] }} slot msg:</text>
<text id="slot-msg-true">{{ msg }}</text>
<script setup lang="uts">
</view>
import Foo from './Foo-composition.uvue'
</template>
</script>
<template v-if="msgFalse['isShow']" #[msgFalse['name']]="{ msg }">
<view class="mb-10 flex justify-between flex-row">
<text>{{ msgFalse['name'] }} slot msg:</text>
<text id="slot-msg-false">{{ msg }}</text>
</view>
</template>
<template #footer="{ arr }">
<view class="mb-10 flex justify-between flex-row">
<text>footer slot arr:</text>
<text id="slot-footer">{{ JSON.stringify(arr) }}</text>
</view>
</template>
</Foo>
</view>
</template>
<script setup lang="uts">
import Foo from './Foo-composition.uvue'
const msgTrue = ref({
isShow: true,
name: 'msgTrue'
})
const msgFalse = ref({
isShow: false,
name: 'msgFalse'
})
</script>
\ No newline at end of file
pages/directive/v-slot/v-slot-options.uvue
浏览文件 @
b043eb7e
...
@@ -13,6 +13,24 @@
...
@@ -13,6 +13,24 @@
<text id="slot-default">{{ num }}</text>
<text id="slot-default">{{ num }}</text>
</view>
</view>
</template>
</template>
<template v-for="item in 2" #[`num${item}`]="{ num }">
<view class="mb-10 flex justify-between flex-row">
<text>num{{ item }} slot:</text>
<text :id="`slot-num${item}`">{{ num }}</text>
</view>
</template>
<template v-if="msgTrue['isShow']" #[msgTrue['name']]="{ msg }">
<view class="mb-10 flex justify-between flex-row">
<text>{{ msgTrue['name'] }} slot msg:</text>
<text id="slot-msg-true">{{ msg }}</text>
</view>
</template>
<template v-if="msgFalse['isShow']" #[msgFalse['name']]="{ msg }">
<view class="mb-10 flex justify-between flex-row">
<text>{{ msgFalse['name'] }} slot msg:</text>
<text id="slot-msg-false">{{ msg }}</text>
</view>
</template>
<template #footer="{ arr }">
<template #footer="{ arr }">
<view class="mb-10 flex justify-between flex-row">
<view class="mb-10 flex justify-between flex-row">
<text>footer slot arr:</text>
<text>footer slot arr:</text>
...
@@ -26,6 +44,18 @@
...
@@ -26,6 +44,18 @@
<script lang="uts">
<script lang="uts">
import Foo from './Foo-options.uvue'
import Foo from './Foo-options.uvue'
export default {
export default {
components: {Foo}
components: {Foo},
data(){
return {
msgTrue: {
isShow: true,
name: 'msgTrue'
},
msgFalse: {
isShow: false,
name: 'msgFalse'
}
}
}
}
}
</script>
</script>
pages/directive/v-slot/v-slot.test.js
浏览文件 @
b043eb7e
...
@@ -11,8 +11,18 @@ describe('v-slot', () => {
...
@@ -11,8 +11,18 @@ describe('v-slot', () => {
const
slotHeader
=
await
page
.
$
(
'
#slot-header
'
)
const
slotHeader
=
await
page
.
$
(
'
#slot-header
'
)
expect
(
await
slotHeader
.
text
()).
toBe
(
'
foo msg
'
)
expect
(
await
slotHeader
.
text
()).
toBe
(
'
foo msg
'
)
const
slotContent
=
await
page
.
$
(
'
#slot-default
'
)
const
slotDefault
=
await
page
.
$
(
'
#slot-default
'
)
expect
(
await
slotContent
.
text
()).
toBe
(
'
0
'
)
expect
(
await
slotDefault
.
text
()).
toBe
(
'
0
'
)
const
slotNum1
=
await
page
.
$
(
'
#slot-num1
'
)
expect
(
await
slotNum1
.
text
()).
toBe
(
'
0
'
)
const
slotNum2
=
await
page
.
$
(
'
#slot-num2
'
)
expect
(
await
slotNum2
.
text
()).
toBe
(
'
0
'
)
const
slotMsgTrue
=
await
page
.
$
(
'
#slot-msg-true
'
)
expect
(
await
slotMsgTrue
.
text
()).
toBe
(
'
foo msg
'
)
const
slotMsgFalse
=
await
page
.
$
(
'
#slot-msg-false
'
)
expect
(
slotMsgFalse
).
toBe
(
null
)
const
slotFooter
=
await
page
.
$
(
'
#slot-footer
'
)
const
slotFooter
=
await
page
.
$
(
'
#slot-footer
'
)
expect
(
await
slotFooter
.
text
()).
toBe
(
'
["a","b","c"]
'
)
expect
(
await
slotFooter
.
text
()).
toBe
(
'
["a","b","c"]
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录