美文网首页
解决vue3 TypeError: parentComponen

解决vue3 TypeError: parentComponen

作者: 太_2_真_人 | 来源:发表于2023-05-11 11:45 被阅读0次

    报错详情:

    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动态组件添加一个唯一属性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>
    

    相关文章

      网友评论

          本文标题:解决vue3 TypeError: parentComponen

          本文链接:https://www.haomeiwen.com/subject/mkmqwrtx.html