Kaynağa Gözat

feat: export defineRender runtime function

三咲智子 Kevin Deng 2 yıl önce
ebeveyn
işleme
2f82c43014

+ 23 - 0
packages/runtime-core/src/apiSetupHelpers.ts

@@ -20,6 +20,7 @@ import type {
   ComponentOptionsWithoutProps,
   ComponentOptionsWithoutProps,
   ComputedOptions,
   ComputedOptions,
   MethodOptions,
   MethodOptions,
+  RenderFunction,
 } from './componentOptions'
 } from './componentOptions'
 import type {
 import type {
   ComponentObjectPropsOptions,
   ComponentObjectPropsOptions,
@@ -313,6 +314,28 @@ type PropsWithDefaults<
     : boolean
     : boolean
 }
 }
 
 
+/**
+ * (**Experimental**) Vue `<script setup>` compiler macro for declaring
+ * the render function.
+ *
+ * The first argument can be a JSX element or a render function.
+ *
+ * @example
+ * ```ts
+ * // JSX element
+ * defineRender(<div>hello</div>)
+ *
+ * // Render function
+ * defineRender(() => <div>hello</div>)
+ * defineRender(() => h('div', 'hello'))
+ * ```
+ */
+export function defineRender(renderFn: JSX.Element | RenderFunction): void {
+  if (__DEV__) {
+    warnRuntimeUsage('defineRender')
+  }
+}
+
 /**
 /**
  * Vue `<script setup>` compiler macro for providing props default values when
  * Vue `<script setup>` compiler macro for providing props default values when
  * using type-based `defineProps` declaration.
  * using type-based `defineProps` declaration.

+ 1 - 0
packages/runtime-core/src/index.ts

@@ -73,6 +73,7 @@ export {
   defineOptions,
   defineOptions,
   defineSlots,
   defineSlots,
   defineModel,
   defineModel,
+  defineRender,
   withDefaults,
   withDefaults,
   type DefineProps,
   type DefineProps,
   type ModelRef,
   type ModelRef,