From 3e474079e0ac9d21daaeaf6d06999934ebbc40e0 Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Fri, 6 Feb 2026 18:00:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(mp-toutiao):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BC=8F=E7=88=B6=E5=AD=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=20inject=20=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/runtime/componentLifetimes.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts index 39c4a3081c..c351364e46 100644 --- a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts +++ b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts @@ -18,12 +18,14 @@ import { import { $createComponent, $destroyComponent, + findVmByVueId, initComponentInstance, initMocks, initRefs, initVueIds, } from '@dcloudio/uni-mp-core' import { ON_READY } from '@dcloudio/uni-shared' +import { instances } from './parseComponentOptions' const fixAttached = __PLATFORM__ === 'mp-toutiao' @@ -57,6 +59,28 @@ export function initLifetimes({ mpInstance.route = mpInstance.__route__ } + // 在创建 Vue 组件实例之前,先查找父组件,以支持组合式 API 的 inject + if (mpType === 'component') { + const webviewId = mpInstance.__webviewId__ + '' + const vuePid = relationOptions.vuePid + + let parentVm + if (vuePid) { + // 尝试从页面查找父组件 + const pageVm = instances[webviewId + '_0'] as ComponentPublicInstance + if (pageVm) { + parentVm = findVmByVueId(pageVm, vuePid) + } + } else { + // 如果 vuePid 不存在,则认为当前组件的父是页面 + parentVm = instances[webviewId + '_0'] + } + + if (parentVm) { + relationOptions.parent = parentVm + } + } + const props = findPropsData(properties, mpType === 'page') this.$vm = $createComponent( From 287eabbb50058784cf109090a9cc792a5ef1b332 Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Fri, 6 Feb 2026 20:42:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(mp-toutiao):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/runtime/componentLifetimes.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts index c351364e46..883bfd80d4 100644 --- a/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts +++ b/packages/uni-mp-toutiao/src/runtime/componentLifetimes.ts @@ -59,25 +59,27 @@ export function initLifetimes({ mpInstance.route = mpInstance.__route__ } - // 在创建 Vue 组件实例之前,先查找父组件,以支持组合式 API 的 inject - if (mpType === 'component') { - const webviewId = mpInstance.__webviewId__ + '' - const vuePid = relationOptions.vuePid + if (__PLATFORM__ === 'mp-toutiao') { + // 在创建 Vue 组件实例之前,先查找父组件,以支持组合式 API 的 inject + if (mpType === 'component') { + const webviewId = mpInstance.__webviewId__ + '' + const vuePid = relationOptions.vuePid - let parentVm - if (vuePid) { - // 尝试从页面查找父组件 - const pageVm = instances[webviewId + '_0'] as ComponentPublicInstance - if (pageVm) { - parentVm = findVmByVueId(pageVm, vuePid) + let parentVm + if (vuePid) { + // 尝试从页面查找父组件 + const pageVm = instances[webviewId + '_0'] as ComponentPublicInstance + if (pageVm) { + parentVm = findVmByVueId(pageVm, vuePid) + } + } else { + // 如果 vuePid 不存在,则认为当前组件的父是页面 + parentVm = instances[webviewId + '_0'] } - } else { - // 如果 vuePid 不存在,则认为当前组件的父是页面 - parentVm = instances[webviewId + '_0'] - } - if (parentVm) { - relationOptions.parent = parentVm + if (parentVm) { + relationOptions.parent = parentVm + } } }