官方文档
    参考文章

    1. <template>
    2. <div>
    3. 异步组件测试
    4. 点击按钮后
    5. 第一个延迟300毫秒,从服务器加载
    6. 第二个不延迟从服务器加载
    7. <template v-if="show">
    8. <later></later>
    9. <later2></later2>
    10. </template>
    11. <button @click="toggle">加载</button>
    12. </div>
    13. </template>
    14. <script>
    15. import Vue from 'vue';
    16. const later = Vue.component('later', function (resolve) {
    17. setTimeout(function () {
    18. require(['./later.vue'], resolve)
    19. }, 3000);
    20. });
    21. const later2 = Vue.component('later2', function (resolve) {
    22. require(['./later2.vue'], resolve)
    23. });
    24. export default{
    25. data: function () {
    26. return {
    27. show: false
    28. };
    29. },
    30. components: {later, later2,},
    31. methods: {
    32. toggle:function () {
    33. this.show = !this.show;
    34. }
    35. },
    36. }
    37. </script>