Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue3): 支持vue3类组件 #11436

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions packages/taro-plugin-vue3/src/runtime/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
App,
Component,
ComponentPublicInstance,
ComponentOptions,
VNode,
h as createElement
} from '@vue/runtime-core'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -125,11 +128,11 @@ export function createVue3App (app: App<TaroElement>, 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()
}

Expand Down Expand Up @@ -216,3 +219,7 @@ export function createVue3App (app: App<TaroElement>, h: typeof createElement, c

return appConfig
}

function isClassComponent (value: unknown) {
return isFunction(value) && '__vccOpts' in value
}