解決vue3 TypeError: parentComponent.ctx.deactivate is not a function 報錯

報錯詳情:

runtime-core.esm-bundler.js:6055 Uncaught (in promise) TypeError: parentComponent.ctx.deactivate is not a function
    at unmount (runtime-core.esm-bundler.js:6055:33)
    at patch (runtime-core.esm-bundler.js:5027:13)
    at sharedContext.activate (runtime-core.esm-bundler.js:2420:13)
    at processComponent (runtime-core.esm-bundler.js:5465:37)
    at patch (runtime-core.esm-bundler.js:5058:21)
    at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5680:17)
    at ReactiveEffect.run (reactivity.esm-bundler.js:185:25)
    at instance.update (runtime-core.esm-bundler.js:5714:56)
    at updateComponent (runtime-core.esm-bundler.js:5539:26)
    at processComponent (runtime-core.esm-bundler.js:5472:13)

router-view官方示例:

<router-view v-slot="{ Component, route }">
      <!-- 注意  v-if="route.meta.isKeepAlive"放在keep-alive標簽上不會生效 -->
      <keep-alive>
        <component :is="Component" v-if="route.meta.isKeepAlive"></component>
      </keep-alive>
      <component :is="Component" v-if="!route.meta.isKeepAlive"></component>
    </router-view>

我們只要為component動態(tài)組件添加一個唯一屬性key即可:

<router-view v-slot="{ Component, route }">
      <!-- 注意  v-if="route.meta.isKeepAlive"放在keep-alive標簽上不會生效 -->
      <keep-alive>
        <component :is="Component" :key="route.name" v-if="route.meta.isKeepAlive"></component>
      </keep-alive>
      <component :is="Component" :key="route.name" v-if="!route.meta.isKeepAlive"></component>
    </router-view>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容