提交 a16a03ac 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): defineSlots

上级 c8a899f7
<template>
<view>
<slot name="header" :msg="msg"></slot>
<slot :num="num"></slot>
<slot name="footer" :arr="arr"></slot>
</view>
</template>
<script setup>
const msg = ref('foo msg')
const num = ref<number>(0)
const arr = ref<string[]>(['a', 'b', 'c'])
defineSlots<{
default(props : { msg : string }) : any,
header(props : { num : string }) : any,
footer(props : { arr : string[] }) : any
}>()
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-slots/define-slots'
describe('defineSlots', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
let page = null
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('basic', async () => {
const slotHeader = await page.$('#slot-header')
expect(await slotHeader.text()).toBe('header slot msg: foo msg')
const slotContent = await page.$('#slot-default')
expect(await slotContent.text()).toBe('default slot num: 0')
const slotFooter = await page.$('#slot-footer')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
})
\ No newline at end of file
<template>
<view class="page"> defineSlots </view>
<view class="page">
<Foo>
<template #header="{msg}">
<text id="slot-header">header slot msg: {{msg}}</text>
</template>
<template #default="{num}">
<text id="slot-default" class="uni-common-mt">default slot num: {{num}}</text>
</template>
<template #footer="{arr}">
<text id="slot-footer" class="uni-common-mt">footer slot arr: {{arr}}</text>
</template>
</Foo>
</view>
</template>
<script setup></script>
<script setup>
import Foo from './Foo.uvue'
</script>
\ No newline at end of file
......@@ -65,7 +65,7 @@
{
name: 'defineSlots',
url: 'define-slots',
enable: false,
enable: true,
},
{
name: 'useSlots',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册