瀏覽代碼

feat: export defineRender runtime function

三咲智子 Kevin Deng 2 年之前
父節點
當前提交
2f82c43014
共有 2 個文件被更改,包括 24 次插入0 次删除
  1. 23 0
      packages/runtime-core/src/apiSetupHelpers.ts
  2. 1 0
      packages/runtime-core/src/index.ts

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

@@ -20,6 +20,7 @@ import type {
   ComponentOptionsWithoutProps,
   ComputedOptions,
   MethodOptions,
+  RenderFunction,
 } from './componentOptions'
 import type {
   ComponentObjectPropsOptions,
@@ -313,6 +314,28 @@ type PropsWithDefaults<
     : 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
  * using type-based `defineProps` declaration.

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

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