vue性能优化-------vendor优化详细用法(瘦身),减小体积,引入cdn

vue性能优化-------vendor优化详细用法(瘦身),减小体积,引入cdn
原创ChrisWang_ 最后发布于2019-05-24 10:25:58 阅读数 1332  收藏
展开
vue性能优化方面有一个是关于vendor的优化,vue其他方面的优化产考https://blog.csdn.net/Chris__wang/article/details/90477555

当项目打包的时候,会将ElementUI,Vue,Vuex,axios,VueRouter等都打包进vendor.js里面,导致最后的vendor.js有900k之多

页面访问的时候会很浪费时间,所以根据网上提供的方法,这些比较占资源的插件引入cdn,速度会快很多,下面是详细用法

main.js里面引入组件,这里面一定要引入,不然本地项目跑步起来,其中注意  ELEMENT 要大写,因为插件里面定义的就是大写

import Vue from 'vue';
import ELEMENT from 'element-ui';
import App from './App';
import router from './router';
import VueAwesomeSwiper from 'vue-awesome-swiper';
 
import 'swiper/dist/css/swiper.css';
 
import 'font-awesome/css/font-awesome.css';
 
import axios from 'axios';
Vue.use(ELEMENT)
Vue.use(VueAwesomeSwiper)
Vue.use(swiper);
Vue.config.productionTip = false
Vue.prototype.axios = axios;
Vue.prototype.baseUrl = './static';
 
 
new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
})
接着在index.html中引入CDN

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico">
        <link rel="stylesheet" href="https://cdn.bootcss.com/element-ui/2.8.2/theme-chalk/index.css">
        <script  type="text/javascript" src="http://api.map.baidu.com/getscript?v=3.0&ak=cw8GwPA7uInfpRok8fRlNqVKroLwbpIO" ></script>
        <script src="https://cdn.bootcss.com/vue/2.5.2/vue.min.js"></script>
        <script src="https://cdn.bootcss.com/vue-router/3.0.6/vue-router.min.js"></script> 
        <script src="https://cdn.bootcss.com/element-ui/2.8.2/index.js"></script>
        <title>首页</title>
    </head>
    <body>
        <div id="app"></div>
    </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值