vue + elementUI 項目首屏速度優化


vue+elementUI項目打包后,首頁加載時間較長,有很多方面值得深入研究、優化的地方,主要從以下二個方面着手:

1,element-ui 按需引入

(1)首先執行: 

npm install babel-plugin-component -D

(2)然后在babelrc中的plugins配置:

[
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ],

(3)在main.js里配置:

import { Button} from 'element-ui';

Vue.component(Button.name, Button);

 

2,vue-router 路由懶加載

(1)首先執行:

npm install babel-plugin-syntax-dynamic-import -D

(2)然后在babelrc中的plugins配置:

"syntax-dynamic-import"

(3)改寫router.config.js里的路由:

const Login = () => import('./components/Login.vue');

export default [
  {
    name:'login',
    path:'/login',
    component:Login
  }
]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM