App.vue 591 B

123456789101112131415161718192021222324252627282930
  1. <template>
  2. <div class="app">
  3. <h3>我是App组件</h3>
  4. <Suspense>
  5. <template v-slot:default>
  6. <Child/>
  7. </template>
  8. <template v-slot:fallback>
  9. <h3>稍等,加载中...</h3>
  10. </template>
  11. </Suspense>
  12. </div>
  13. </template>
  14. <script>
  15. // import Child from './components/Child'//静态引入
  16. import {defineAsyncComponent} from 'vue'
  17. const Child = defineAsyncComponent(()=>import('./components/Child')) //异步引入(动态引入)
  18. export default {
  19. name:'App',
  20. components:{Child},
  21. }
  22. </script>
  23. <style>
  24. .app{
  25. background-color: gray;
  26. padding: 10px;
  27. }
  28. </style>