vue keep-alive在生产环境失效

 项目要求实现类似浏览器标签页的需求,标签页切换缓存之前的数据

使用keep-alive实现,在本地正常,但是打包放到线上就失效了

cachedViews缓存组件的name
路由文件中,每个页面都是有name属性的
<keep-alive :include="cachedViews">
         <router-view class="content-container" :key="key" />
</keep-alive>


解决方法:
在开发环境,会直接把类名作为组件的name值,但是build时类名会被忽略掉,因此需要手动加上name属性。
@Component{
    name: 'componentName'
}
export default class Components extends Vue {}









原文地址:https://www.cnblogs.com/gxp69/p/14785236.html