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

feat(render function): 补充 render 自定义组件更新 props 示例及测试 issue:11752

上级 aaa79b4c
<template>
<view>
<text class="uni-common-mt bold component-for-h-function">component for h()</text>
<slot />
</view>
</template>
<template>
<view>
<text class="uni-common-mt bold component-for-h-function">component for h()</text>
<text id="comp-for-h-function-msg">{{msg}}</text>
<slot />
</view>
</template>
<script>
export default {
props: {
msg: {
type: String
}
}
}
</script>
......@@ -5,7 +5,7 @@ const msg = ref('default msg')
// 故意外部声明为UTSJSONObject
const msgProps = { class: 'uni-common-mt msg', style: { color: 'blue' } }
const render = ():VNode => h('view', { class: 'page' }, [
h(CompForHFunction, {}, (): VNode[] => [h('text', { class: 'comp-slot' }, 'component slot')]),
h(CompForHFunction, { msg: msg.value }, (): VNode[] => [h('text', { class: 'comp-slot' }, 'component slot')]),
h('text', msgProps, msg.value),
h(
'button',
......
<script lang="uts">
import CompForHFunction from '@/components/CompForHFunction.uvue'
// 故意外部声明为UTSJSONObject
const msgProps = { class: 'uni-common-mt msg', style: { color: 'blue' } }
export default {
data() {
return {
msg: 'default msg'
}
},
render(): VNode {
return h('view', { class: 'page' }, [
h(CompForHFunction, {}, (): VNode[] => [h('text', { class: 'comp-slot' }, 'component slot')]),
h('text', msgProps, this.msg),
h(
'button',
{
class: 'uni-common-mt btn',
type: 'primary',
onClick: () => {
this.msg = 'new msg'
}
},
'click'
)
])
}
}
</script>
<style>
.btn {
color: red;
}
<script lang="uts">
import CompForHFunction from '@/components/CompForHFunction.uvue'
// 故意外部声明为UTSJSONObject
const msgProps = { class: 'uni-common-mt msg', style: { color: 'blue' } }
export default {
data() {
return {
msg: 'default msg'
}
},
render() : VNode {
return h('view', { class: 'page' }, [
h(CompForHFunction, { msg: this.msg }, () : VNode[] => [h('text', { class: 'comp-slot' }, 'component slot')]),
h('text', msgProps, this.msg),
h(
'button',
{
class: 'uni-common-mt btn',
type: 'primary',
onClick: () => {
this.msg = 'new msg'
}
},
'click'
)
])
}
}
</script>
<style>
.btn {
color: red;
}
</style>
\ No newline at end of file
......@@ -25,12 +25,16 @@ describe('render-function render', () => {
let msgEl = await page.$('.msg')
expect(await msgEl.text()).toEqual('default msg')
compForHFunctionMsg = await page.$('#comp-for-h-function-msg')
expect(await compForHFunctionMsg.text()).toEqual('default msg')
const btnEl = await page.$('.btn')
expect(await btnEl.property('type')).toBe('primary')
await btnEl.tap()
msgEl = await page.$('.msg')
expect(await msgEl.text()).toEqual('new msg')
compForHFunctionMsg = await page.$('#comp-for-h-function-msg')
expect(await compForHFunctionMsg.text()).toEqual('new msg')
}
it('render options API', async () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册