美文网首页
性能优化之Vue组件懒加载(一)

性能优化之Vue组件懒加载(一)

作者: 卓三阳 | 来源:发表于2018-07-09 22:29 被阅读293次

通用的Vue 2.x 组件级懒加载解决方案(Vue Lazy Component ),非常适合长页面加载。

xunleif2e/vue-lazy-component

下面的代码这是推迟了模块的渲染和模块内的资源的加载,如果我们需要更进一步,连模块本身的代码也是懒加载,就像 AMD 那样异步按需加载,这个将在第二部分尝试。

css

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
#header{
   height:2000px;
   background-color: #e3e4e2;
}
#floor1{
  height:200px;
  background-color: #e46690;
}
#floor2{
  height:200px;
  background-color: #f1f106;
}
#floor3{
  height:200px;
  background-color: #06f1f1;
}

App.vue

<template>
  <div id="app">
    <Header>
    </Header>
    <Floor id="floor1"/>
    <Floor id="floor2"/>
    <Floor id="floor3"/>
  </div>
</template>

<script>
import '@/assets/css/main.css' 
import Header from './components/Header'
import Floor from './components/Floor'
export default {
  name: 'App',
  data(){
    return{
      title:"this is a title",
    }
  },
  methods:{
   
   },
 components: {
    Header,
    Floor
  }
}
</script>

Floor.vue

<template>
  <vue-lazy-component threshold="200px" @init="init" >
  <div>this is floor</div>
  <div slot="skeleton">
     this is skeleton
  </div>
</vue-lazy-component>

</template>  


<script>
import { component as VueLazyComponent } from '@xunlei/vue-lazy-component'

export default{
  methods:{
    init(){
      for(var i=0;i<100000;i++){
        for(var j=0;j<1000;j++){
           j+=1;
           j-=1;
        }
      }
      console.log('初始化中...');
    }
  },
  components: {
    'vue-lazy-component': VueLazyComponent
  }
}
</script>

参考:
性能优化之组件懒加载: Vue Lazy Component 介绍
github仓库

相关文章

  • Vue路由异步组件

    vue异步组件和懒加载可以优化vue的性能 一、 原理 利用webpack对代码进行分割是懒加载的前提,懒加载就是...

  • 性能优化之Vue组件懒加载(一)

    通用的Vue 2.x 组件级懒加载解决方案(Vue Lazy Component ),非常适合长页面加载。 xun...

  • 2019-05-10

    vue 组件按需引用,vue-router懒加载,vue打包优化,加载动画 当打包构建应用时,Javascript...

  • 复习3

    vue路由懒加载 1.vue路由懒加载解决的什么 问题:解决打包后文件过大的问题,从而优化页面加载,提升性能 注意...

  • 性能优化之Vue组件懒加载(二)

    上一次我们实现了模块的渲染和模块内的资源的加载,但是我们并没有真正实现组件的异步加载。 1.什么是异步组件? 异步...

  • vue-01

    vue+webpack 优化 一.异步加载 1.异步加载组件,其实就是组件懒加载。可以理解为:当我需要使用组件的时...

  • vue 性能优化点

    vue项目中,经常会遇到一些性能优化点,以下就是我在工作中,总结的优化点 vue 性能优化点 1,路由懒加载 2,...

  • 在React中可以用来优化组件性能的方法

    在React中可以用来优化组件性能的方法有: 组件懒加载(React.lazy(...)和 ) Pure Comp...

  • iOS性能优化之页面加载速率

    iOS性能优化之页面加载速率 iOS性能优化之页面加载速率

  • 前端性能优化之Lazyload

    前端性能优化之Lazyload @(冬晨)[JavaScript|技术分享|懒加载] [TOC] Lazyload...

网友评论

      本文标题:性能优化之Vue组件懒加载(一)

      本文链接:https://www.haomeiwen.com/subject/cpqxpftx.html