From f50655dbf77ae3d2a6ab1169ad6e9ee7fcdbd3be Mon Sep 17 00:00:00 2001 From: agileago Date: Fri, 11 Mar 2022 18:33:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(vue3):=20=E6=94=AF=E6=8C=81vue3?= =?UTF-8?q?=E7=B1=BB=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-plugin-vue3/src/runtime/connect.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/taro-plugin-vue3/src/runtime/connect.ts b/packages/taro-plugin-vue3/src/runtime/connect.ts index df5220ca783d..e659e05d98a8 100644 --- a/packages/taro-plugin-vue3/src/runtime/connect.ts +++ b/packages/taro-plugin-vue3/src/runtime/connect.ts @@ -11,6 +11,7 @@ import type { App, Component, ComponentPublicInstance, + ComponentOptions, VNode, h as createElement } from '@vue/runtime-core' @@ -64,6 +65,8 @@ function setReconciler () { function createVue3Page (h: typeof createElement, id: string) { return function (component): VNode { + // 处理类组件 + component = isClassComponent(component) ? component.__vccOpts : component const inject = { props: { tid: String @@ -125,11 +128,11 @@ export function createVue3App (app: App, h: typeof createElement, c let pages: VNode[] = [] let appInstance: ComponentPublicInstance - ensure(!isFunction(app._component), '入口组件不支持使用函数式组件') + ensure(!(isFunction(app._component) && !isClassComponent(app._component)), '入口组件不支持使用函数式组件') setReconciler() - app._component.render = function () { + ;(app._component as ComponentOptions).render = function () { return pages.slice() } @@ -216,3 +219,7 @@ export function createVue3App (app: App, h: typeof createElement, c return appConfig } + +function isClassComponent (value: unknown) { + return isFunction(value) && '__vccOpts' in value +} From 986bb01823a5edb00f82a2f2ae11e04a7b5f5958 Mon Sep 17 00:00:00 2001 From: agileago Date: Mon, 14 Mar 2022 10:02:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0vue3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=BF=AB=E7=85=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/__tests__/__snapshots__/vue3.spec.ts.snap | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/taro-mini-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap b/packages/taro-mini-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap index ab17660a35d4..e634e87bbd85 100644 --- a/packages/taro-mini-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap +++ b/packages/taro-mini-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap @@ -528,6 +528,7 @@ require(\\"./taro\\"); function createVue3Page(h, id) { return function(component) { var _a; + component = isClassComponent(component) ? component.__vccOpts : component; var inject = { props: { tid: String @@ -575,7 +576,7 @@ require(\\"./taro\\"); var _Object$create; var pages = []; var appInstance; - undefined(!isFunction(app._component), \\"\\\\u5165\\\\u53e3\\\\u7ec4\\\\u4ef6\\\\u4e0d\\\\u652f\\\\u6301\\\\u4f7f\\\\u7528\\\\u51fd\\\\u6570\\\\u5f0f\\\\u7ec4\\\\u4ef6\\"); + undefined(!(isFunction(app._component) && !isClassComponent(app._component)), \\"\\\\u5165\\\\u53e3\\\\u7ec4\\\\u4ef6\\\\u4e0d\\\\u652f\\\\u6301\\\\u4f7f\\\\u7528\\\\u51fd\\\\u6570\\\\u5f0f\\\\u7ec4\\\\u4ef6\\"); setReconciler(); app._component.render = function() { return pages.slice(); @@ -650,6 +651,9 @@ require(\\"./taro\\"); taro_runtime[\\"Current\\"].app = appConfig; return appConfig; } + function isClassComponent(value) { + return isFunction(value) && \\"__vccOpts\\" in value; + } var runtime_hooks = taro_runtime[\\"container\\"].get(taro_runtime[\\"SERVICE_IDENTIFIER\\"].Hooks); runtime_hooks.initNativeApiImpls || (runtime_hooks.initNativeApiImpls = []); runtime_hooks.initNativeApiImpls.push((function(taro) {