路由切换跳转时,发现一个页面的接口和页面展示每次进入都会调用created。keep-alive缓存页面没有效果,代码如下
keep-alive页面
<section class="app-main"> <transition name="fade-transform" mode="out-in"> <keep-alive :include="cachedViews"> <router-view :key="this.$route.path" /> </keep-alive> </transition> </section>View Code
路由配置
{ path: '/contract/template/list', name: 'contract_template_list', component: () => import('@/views/contract/template/list.vue'), meta:{ title:"合同模板管理", component_name:'contract_template_list', requiresAuth:true } }View Code
组件页面
import edit from './edit.vue'; import {commonUse} from '@/utils/mixins/mixinsHelper.js'; export default { mixins:[commonUse], data() { return { ... } }, components: { edit }, created(){ this.getBillTypes() } }View Code
经排查,发现是组件的name没有,加上之后就正常了,另外要注意组件的name要和路由里的name一直
import edit from './edit.vue'; import {commonUse} from '@/utils/mixins/mixinsHelper.js'; export default { name:"contract_template_list", mixins:[commonUse], data() { return { ... } }, components: { edit }, created(){ this.getBillTypes() } }
标签:生命周期,name,created,edit,list,Vue,template,import From: https://www.cnblogs.com/helloStone/p/18284333