Skip to content

Commit 5f8bd91

Browse files
committed
feat: add If component for conditional rendering
1 parent b89a486 commit 5f8bd91

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/components/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { SetupContext } from 'vue'
2+
import type { JSX } from 'vue/jsx-runtime'
3+
4+
interface IfProps {
5+
/*判断条件*/
6+
condition: any
7+
}
8+
export function If(props: IfProps, ctx: SetupContext) {
9+
if (!props.condition) return null
10+
return ctx.slots.default?.() as unknown as JSX.Element
11+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { Hook } from './decorators/hook'
77
export { createDecorator, getProtoMetadata } from './decorators/util'
88
export * from './helper'
99
export * from './simple-props'
10+
export * from './components'
1011
export { Component, InjectorKey, getCurrentInjector, createCurrentInjector, injectService, provideService } from './di'
1112
export type { ComponentOptions } from './di'
1213
export type {

0 commit comments

Comments
 (0)