zoukankan      html  css  js  c++  java
  • [Vue] Load components when needed with Vue async components

    In large applications, dividing the application into smaller chunks is often times necessary. In this lesson, we will look at how vue loads async components into your application.

    <template>
      <div>
        <section class="pa2">
          <h2>Lazy loading...</h2>
          <button @click="show = true">Lazy load</button>
          <div v-if="show">
            <Async></Async>
          </div>
        </section>
      </div>
    </template>
    
    <script>
    
      const Async = resolve => {
        console.log('loading...')
        setTimeout(() => {
          require(['~components/async.vue'], resolve)
          console.log('loaded')
        }, 1000)
      }
    
      export default {
        components: {
          Async
        },
        data () {
          return {
            show: false
          }
        }
      }
    </script>
  • 相关阅读:
    2017.11.20
    第8次
    作业 lianxi
    java 7个练习题
    java 2.15
    java 2.6
    jsp变量和方法的声明
    jsp 基本标签从头练习
    15
    14
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7240261.html
Copyright © 2011-2022 走看看