• 【vue】组件使用Deferred特性


    延迟加载组件

    defer的意思是"延迟",所以deferred对象的含义就是"延迟"到未来某个点再执行。

    <template>
      <div>
        <h2>I'm an heavy page</h2>
    
        <template v-if="defer(2)">
          <Heavy v-for="n in 10" :key="n"/>
        </template>
    
        <Heavy v-if="defer(3)" class="super-heavy" :n="9999999"/>
      </div>
    </template>
    
    <script>
    import Defer from '@/mixins/Defer'
    
    export default {
      mixins: [
        Defer()
      ]
    }
    </script>

    混合

    export default function (count = 10) {
      return {
        data () {
          return {
            displayPriority: 0
          }
        },
    
        mounted () {
          this.runDisplayPriority()
        },
    
        methods: {
          runDisplayPriority () {
            const step = () => {
              requestAnimationFrame(() => {
                this.displayPriority++
                if (this.displayPriority < count) {
                  step()
                }
              })
            }
            step()
          },
    
          defer (priority) {
            return this.displayPriority >= priority
          }
        }
      }
    }

    延迟组件加载对性能提升有很大的帮助

  • 相关阅读:
    poj 2312 Battle City
    poj 2002 Squares
    poj 3641 Pseudoprime numbers
    poj 3580 SuperMemo
    poj 3281 Dining
    poj 3259 Wormholes
    poj 3080 Blue Jeans
    poj 3070 Fibonacci
    poj 2887 Big String
    poj 2631 Roads in the North
  • 原文地址:https://www.cnblogs.com/wuxianqiang/p/10621396.html
Copyright © 2020-2023  润新知