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

feat: dynamic component

上级 4b29097e
<template>
<text class="component-bar">this is component Bar</text>
</template>
<template>
<text class="component-foo">this is component Foo</text>
</template>
\ No newline at end of file
...@@ -248,6 +248,12 @@ ...@@ -248,6 +248,12 @@
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{
"path": "pages/rendering/component/component",
"style": {
"navigationBarTitleText": "component"
}
},
{ {
"path": "pages/examples/nested-component-communication/nested-component-communication", "path": "pages/examples/nested-component-communication/nested-component-communication",
"style": { "style": {
......
...@@ -215,11 +215,16 @@ ...@@ -215,11 +215,16 @@
url: 'render', url: 'render',
enable: false, enable: false,
}, },
{ {
name: 'slots', name: 'slots',
url: 'slots', url: 'slots',
enable: true, enable: true,
}, },
{
name: 'component',
url: 'component',
enable: true,
},
] as PageItem[], ] as PageItem[],
}, },
{ {
......
describe('/pages/rendering/component/component', () => {
let page
beforeAll(async () => {
page = await program.reLaunch('/pages/rendering/component/component')
await page.waitFor('view')
})
it('basic', async () => {
let fooList = await page.$$('.component-foo')
expect(fooList.length).toBe(2)
expect(await fooList[0].text()).toBe('this is component Foo')
expect(await fooList[1].text()).toBe('this is component Foo')
let barList= await page.$$('.component-bar')
expect(barList.length).toBe(0)
await page.callMethod('changeCurrentComponent')
fooList = await page.$$('.component-foo')
expect(fooList.length).toBe(0)
barList= await page.$$('.component-bar')
expect(barList.length).toBe(2)
expect(await barList[0].text()).toBe('this is component Bar')
expect(await barList[1].text()).toBe('this is component Bar')
})
});
\ No newline at end of file
<template>
<view class="container">
<component :is="currentComponentStr" />
<component :is="currentComponentInstance" />
<button @click="changeCurrentComponent">change current component</button>
</view>
</template>
<script lang="uts">
import Foo from '../../../components/Foo.uvue'
import Bar from '../../../components/Bar.uvue'
export default {
components: {
Foo,
Bar
},
data() {
return {
currentComponentStr: 'Foo',
currentComponentInstance: Foo,
}
},
methods: {
changeCurrentComponent() {
if (this.currentComponentStr === 'Foo') {
this.currentComponentStr = 'Bar'
this.currentComponentInstance = Bar
} else {
this.currentComponentStr = 'Foo'
this.currentComponentInstance = Foo
}
}
}
}
</script>
<style>
.item {
display: flex;
flex-direction: row;
margin: 15px;
border: #eee solid 1px;
}
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册