vue问题解决:Vue packages version mismatch版本始终不对的解决、TypeError: parentComponent.ctx.deactivate is not a function解决

一、Vue packages version mismatch: 版本始终不对的解决方案

1、npm run dev 的时候报错:

复制代码
Vue packages version mismatch:
- vue@2.6.1
- vue-template-compiler@2.7.8
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify 
should bump vue-template-compiler to the latest.
复制代码

  出现这种错误之后可以使用命令,将vue的版本改成和vue-template-compiler的版本一致,使用命令:npm install vue@2.7.8 --save,然后直接运行就可以了

2、vue执行了npm i vue@2.6.14的更新命令, 就会出现如下提示:

复制代码
error  in ./src/pages/system/permissionsmanagement.vue
 
Module build failed: Error:
Vue packages version mismatch:
- vue@2.6.14 (/Users/dx/Documents/***/node_modules/vue/dist/vue.runtime.common.js)
- vue-template-compiler@2.6.11 (/Users/dx/Documents/***/node_modules/vue-template-compiler/package.json)
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify 
should bump vue-template-compiler to the latest.
复制代码

  解决思路:npm i vue-template-compiler 和 vue 版本需要一致

  解决办法:更新vue-template-compiler, 命令行输入:npm i vue-template-compiler@2.6.14(你的vue版本号)

二、TypeError: parentComponent.ctx.deactivate is not a function解决

  当两个组件都可 keepalive 的时候,切换就回报这个错误:runtime-core.esm-bundler.js:6086 Uncaught (in promise) TypeError: parentComponent.ctx.deactivate is not a function

  问题原因:路由的问题

复制代码
// 之前的写法
<router-view v-slot="{ Component, route }">
  <keep-alive v-if="Component">
    <component :is="Component" v-if="route.meta.keepAlive"></component>
  </keep-alive>
  <component :is="Component" v-if="!route.meta.keepAlive"></component>
</router-view>

// 修改正确的写法
<router-view v-slot="{ Component, route }">
  <keep-alive v-if="Component">
    <component :is="Component" :key="route.name" v-if="route.meta.keepAlive"></component>
  </keep-alive>
  <component :is="Component" :key="route.name" v-if="!route.meta.keepAlive"></component>
</router-view>
复制代码

  在路由节点内配置name属性,且保证为唯一标识,或其它唯一标识也行(:key=“route.name”)

  解决:加上 :key="route.name" 这句代码就能解决此报错

posted @   古兰精  阅读(17710)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示