vueRouter4 报错: Failed to execute 'insertBefore' on 'Node': The node before which

676 阅读1分钟

起因是在使用vueRouter中 使用mode'out-in'类型

<router-view v-slot="{ Component, route }">
         <transition name="fade-transform" mode="out-in">
           <Suspense>
             <template #default>
               <component :is="Component" :key="route.path" />
             </template>
             <template #fallback> Loading... </template>
           </Suspense>
         </transition>
 </router-view>

会报这个错误:Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.

解决方案:换回VUE2写法

<transition name="fade-transform" mode="out-in">
           <RouterView></RouterView>
</transition>

或者切换其他的mode类型(手动狗头保命)