-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refactor_schema_expression' of github.com:alibaba/formi…
…ly into refactor_schema_expression
- Loading branch information
Showing
3 changed files
with
338 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<FormProvider :form="form"> | ||
<SchemaField :schema="schema" /> | ||
</FormProvider> | ||
</template> | ||
|
||
<script> | ||
import { createForm } from '@formily/core' | ||
import { FormProvider, createSchemaField } from '@formily/vue' | ||
import { observer } from '@formily/reactive-vue' | ||
// 带有作用域插槽的普通组件 | ||
const TextPreviewer = { | ||
functional: true, | ||
name: 'TextPreviewer', | ||
render(h, context) { | ||
return h('div', {}, [ | ||
context.scopedSlots.default({ | ||
scopedProp: 'default 作用域插槽', | ||
onScopedFunc: ($event) => { | ||
alert($event) | ||
}, | ||
}), | ||
]) | ||
}, | ||
} | ||
// 响应式组件 | ||
const ObservedComponent = observer({ | ||
functional: true, | ||
components: { | ||
TextPreviewer, | ||
}, | ||
render(h, context) { | ||
return h(TextPreviewer, { | ||
scopedSlots: { | ||
default: (props) => context.scopedSlots.default(props), | ||
}, | ||
}) | ||
}, | ||
}) | ||
// 作用域插槽组件 | ||
const ScopedSlotComponent = { | ||
functional: true, | ||
render(h, { props }) { | ||
return h( | ||
'div', | ||
{ | ||
on: { | ||
click: () => { | ||
props.onScopedFunc('作用域插槽传递事件函数,事件发生后进行值的回传') | ||
}, | ||
}, | ||
}, | ||
[props.scopedProp] | ||
) | ||
}, | ||
} | ||
const { SchemaField } = createSchemaField({ | ||
components: { | ||
ObservedComponent, | ||
}, | ||
}) | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
textPreview: { | ||
type: 'string', | ||
'x-component': 'ObservedComponent', | ||
'x-content': { | ||
default: ScopedSlotComponent, | ||
}, | ||
}, | ||
}, | ||
} | ||
export default { | ||
components: { FormProvider, SchemaField }, | ||
data() { | ||
return { | ||
form: createForm(), | ||
schema, | ||
} | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters