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 @ 2017-08-17 09:24  古兰精  阅读(17241)  评论(0编辑  收藏  举报