码迷,mamicode.com
首页 > 其他好文 > 详细

vue的异步组件按需加载

时间:2018-10-08 18:04:45      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:com   java   nts   head   build   class   div   rom   port   

当build打包后,app.js过大的时候,可以考虑用异步组件的方式。

import HomeHeader from "./components/Header";
import HomeSwiper from "./components/Swiper";
import HomeIcons from "./components/Icons";
import HomeRecommend from "./components/Recommend";
import HomeWeekend from "./components/Weekend";

export default {  
    name: "Home", 
    components: {   
        HomeHeader,     
        HomeSwiper,    
        HomeIcons,   
        HomeRecommend,   
        HomeWeekend  
    } 
}

            

  以下是异步组件加载方式:

export default {
  name: ‘Home‘,

  components: { 
    //异步组件加载方式    
    HomeHeader: () => import("./components/Header"),  
    HomeSwiper: () => import("./components/Swiper"),
    HomeIcons: () => import("./components/Icons"),
    HomeRecommend: () => import("./components/Recommend"),   
    HomeWeekend: () => import("./components/Weekend")  
  }
}

  

vue的异步组件按需加载

标签:com   java   nts   head   build   class   div   rom   port   

原文地址:https://www.cnblogs.com/chenlw/p/9755700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!