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

feat(render-function): withDirectives

上级 ec31ab13
......@@ -8,9 +8,12 @@
isMounted: false
}
},
render(instance : ComponentPublicInstance) : VNode {
render() : VNode {
const instance = getCurrentInstance()!.proxy!
const customDirective = {
mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode: VNode | null) {
console.log(el, binding, vnode, prevVNode)
instance.$data['isMounted'] = true
}
} as Directive
......@@ -18,7 +21,7 @@
withDirectives(h('text', 'Hello World'), [[customDirective]]),
h('view', { class: 'mt-10 flex flex-row justify-between' }, [
h('text', {}, `isMounted:`),
h('text', {}, `${instance.$data['isMounted']}`),
h('text', { id: 'is-mounted' }, `${instance.$data['isMounted']}`),
])
])
}
......
<script lang="uts">
import {withDirectives } from 'vue'
import type { DirectiveBinding } from 'vue'
import { withDirectives } from 'vue'
import type { DirectiveBinding } from 'vue'
export default {
data(){
return {
isMounted: false
}
},
// android 端暂不支持
// render 写入 instance 参数编译报错 error: '$render' overrides nothing‌
render(instance: ComponentPublicInstance):VNode {
const customDirective = {
mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode: VNode | null) {
instance.$data['isMounted'] = true
export default {
data() {
return {
isMounted: false
}
} as Directive
return h('view', { class: 'page' }, [
withDirectives(h('text', 'Hello World'), [[customDirective]]),
h('view', { class: 'mt-10 flex flex-row justify-between' }, [
h('text', {}, `isMounted:`),
h('text', {}, `${instance.$data['isMounted']}`),
},
render() : VNode {
const instance = this
const customDirective = {
mounted(el : UniElement, binding : DirectiveBinding, vnode : VNode, prevVNode : VNode | null) {
console.log(el, binding, vnode, prevVNode)
instance.$data['isMounted'] = true
}
} as Directive
return h('view', { class: 'page' }, [
withDirectives(h('text', 'Hello World'), [[customDirective]]),
h('view', { class: 'mt-10 flex flex-row justify-between' }, [
h('text', {}, `isMounted:`),
h('text', { id: 'is-mounted' }, `${instance.$data['isMounted']}`),
])
])
])
}
}
}
</script>
</script>
\ No newline at end of file
const OPTIONS_PAGE_PATH = '/pages/render-function/withDirectives/withDirectives-options'
const COMPOSITION_PAGE_PATH = '/pages/render-function/withDirectives/withDirectives-composition'
describe('withDirectives', () => {
describe('withDirectives', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isWeb = platformInfo.startsWith('web')
const isIos = platformInfo.startsWith('ios')
if (isWeb) {
it("web platform test cannot get render dom", async () => {
expect(1).toBe(1);
});
return
}
let page = null
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor(1000)
await page.waitFor('view')
const image = await program.screenshot();
expect(image).toSaveImageSnapshot();
const isMounted = await page.$('#is-mounted')
expect(await isMounted.text()).toBe('true')
}
it('withDirectives options API', async () => {
......@@ -16,6 +26,11 @@ describe('withDirectives', () => {
})
it('withDirectives composition API', async () => {
await test(COMPOSITION_PAGE_PATH)
if (!isIos) {
await test(COMPOSITION_PAGE_PATH)
}else{
// TODO: ios 端 defineOptions + render 页面空白
expect(1).toBe(1);
}
})
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册