Vue项目中created生命周期重复执行

路由切换跳转时,发现一个页面的接口和页面展示每次进入都会调用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()
    }
}

 

posted @ 2024-07-04 17:47  hello_stone  阅读(304)  评论(0)    收藏  举报