vue#ConcreteComponent TypeScript Examples
The following examples show how to use
vue#ConcreteComponent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormKit.ts From formkit with MIT License | 5 votes |
FormKit = defineComponent({
props,
emits: {
/* eslint-disable @typescript-eslint/no-unused-vars */
input: (_value: any, _node: FormKitNode) => true,
inputRaw: (_value: any, _node: FormKitNode) => true,
'update:modelValue': (_value: any) => true,
node: (node: FormKitNode) => !!node,
submit: (_data: FormKitGroupValue, _node: FormKitNode) => true,
submitRaw: (_event: Event, _node: FormKitNode) => true,
/* eslint-enable @typescript-eslint/no-unused-vars */
},
inheritAttrs: false,
setup(props, context) {
const node = useInput(props, context)
if (!node.props.definition) error(600, node)
if (node.props.definition.component) {
return () =>
h(
node.props.definition?.component as any,
{
context: node.context,
},
{ ...context.slots }
)
}
const schema = ref<FormKitSchemaCondition | FormKitSchemaNode[]>([])
const generateSchema = () => {
const schemaDefinition = node.props?.definition?.schema
if (!schemaDefinition) error(601, node)
schema.value =
typeof schemaDefinition === 'function'
? schemaDefinition({ ...props.sectionsSchema })
: schemaDefinition
}
generateSchema()
// If someone emits the schema event, we re-generate the schema
node.on('schema', generateSchema)
context.emit('node', node)
const library = node.props.definition.library as
| Record<string, ConcreteComponent>
| undefined
// Expose the FormKitNode to template refs.
context.expose({ node })
return () =>
h(
FormKitSchema,
{ schema: schema.value, data: node.context, library },
{ ...context.slots }
)
},
})
Example #2
Source File: RouteLayoutSource.ts From convue with MIT License | 5 votes |
export function createRouterLayout(
resolve: (layoutName: string) => Promise<Component | { default: Component }>,
) {
return defineComponent({
name: 'RouterLayout',
async beforeRouteEnter(to, _from, next) {
const name = to.meta.layout || 'default'
const layoutComp = name
? ((await resolve(name)) as any).default
: undefined
next((vm: any) => {
vm.layoutName = name
if (name && layoutComp)
vm.layouts[name] = layoutComp
})
},
async beforeRouteUpdate(to, _from, next) {
try {
const name = to.meta.layout || 'default'
if (name && !this.layouts[name])
this.layouts[name] = ((await resolve(name)) as any).default
this.layoutName = name
next()
}
catch (error) {
next(error)
}
},
data() {
return {
layoutName: undefined as string | undefined,
layouts: shallowReactive(
Object.create(null) as Record<string, Component>,
),
}
},
render(): VNode {
const layout = this.layoutName && this.layouts[this.layoutName]
if (!layout)
return h('span')
return h(layout as ConcreteComponent, {
key: this.layoutName,
})
},
})
}