diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index 5bf6b42209d93c7f53aa3e2d7ff6b774ceb291c7..75c60a6926eb10faec6b267da96184068126aaab 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -5022,6 +5022,13 @@ function renderSlot(name, props = {}) { if (!vueIds) { return; } + if (!instance.parent && !instance.isMounted) { + // 头条小程序首次 render 时,还没有 parent + onMounted(() => { + renderSlot(name, props); + }, instance); + return; + } const invoker = findScopedSlotInvoker(vueIds.split(',')[0], instance); // 可能不存在,因为插槽不是必需的 if (invoker) { diff --git a/packages/uni-mp-vue/src/helpers/renderSlot.ts b/packages/uni-mp-vue/src/helpers/renderSlot.ts index ed05aa4aebf8898c741efe2031688668459b4dc3..0b70c6acfd08c95a33d9fe41ec445ae4192cd545 100644 --- a/packages/uni-mp-vue/src/helpers/renderSlot.ts +++ b/packages/uni-mp-vue/src/helpers/renderSlot.ts @@ -1,6 +1,6 @@ import type { ComponentInternalInstance } from 'vue' import type { ScopedSlotInvokers } from './withScopedSlot' -import { getCurrentInstance } from 'vue' +import { onMounted, getCurrentInstance } from 'vue' export function renderSlot(name: string, props: Data = {}) { const instance = getCurrentInstance() as ComponentInternalInstance @@ -8,6 +8,13 @@ export function renderSlot(name: string, props: Data = {}) { if (!vueIds) { return } + if (!instance.parent && !instance.isMounted) { + // 头条小程序首次 render 时,还没有 parent + onMounted(() => { + renderSlot(name, props) + }, instance) + return + } const invoker = findScopedSlotInvoker(vueIds.split(',')[0], instance) // 可能不存在,因为插槽不是必需的 if (invoker) {