Vue3.0+vite2 implements dynamic asynchronous component lazy loading

Vue3.0+vite2 implements dynamic asynchronous component lazy loading

Create a Vite project

Performance determines success or failure; Vite is indeed fast;
cmd command line (you have already installed node & npm by default), execute npm init @vitejs/app vue-study – --template vue;
cd to vue-study, npm install (install dependencies); npm run dev (start the project);

Creating Components

Create a new directory called pages, and under pages, create a new directory called contents. Under contents, you can create a specific component directory page. At this time, the directory structure is as follows:

App.vue

<template>
 <p @click="onChangeContents('./pages/contents/gp/gp.vue')">Guo Pei</p>
 <p @click="onChangeContents('./pages/contents/systemManges/xtcs.vue')">System parameters</p>
 <p>{{currentTabComponent}}</p>
 <!-- <Suspense> -->
 <component :is="DefineAsyncComponent({
     //Factory function loader: Modeuls[currentTabComponent],
     // // Default value: Infinity (i.e. never time out, unit: ms)
     timeout: 3000,
    })"></component>
 <!-- </Suspense> -->
</template>
<script lang="ts">
 import {
  defineComponent,
  defineAsyncComponent,
  reactive,
  ref
 } from 'vue'
 export default defineComponent({
  name: 'App',
  setup() {
   //vite loads all modules of the specified path const Modeuls = import.meta.glob('./pages/contents/*/*');
   const onChangeContents = function(URL) {
    currentTabComponent.value = URL;
    console.log(currentTabComponent)
   }
   let currentTabComponent = ref('./pages/contents/systemManges/xtcs.vue');
   const DefineAsyncComponent = defineAsyncComponent;
   return {
    DefineAsyncComponent,
    currentTabComponent,
    onChangeContents,
    Modeuls
   }
  },
 })
</script>

This is the end of this article about vue3.0+vite2 to implement dynamic asynchronous component lazy loading. For more related vue3.0+vite2 dynamic asynchronous lazy loading content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vite builds projects and supports micro frontends
  • This article will show you what Vite does to the browser's request
  • Vite+Electron to quickly build VUE3 desktop applications
  • How to add Vite support to old Vue projects
  • Vite2.0 Pitfalls
  • Implementation of vite+vue3.0+ts+element-plus to quickly build a project
  • Steps to build the vite+vue3+element-plus project
  • Learn the principles of Vite

<<:  Implementation example of nginx access control

>>:  MySQL slow_log table cannot be modified to innodb engine detailed explanation

Recommend

Make your website automatically use IE7 compatibility mode when browsing IE8

Preface To help ensure that your web pages have a ...

18 sets of exquisite Apple-style free icon materials to share

Apple Mug Icons and Extras HD StorageBox – add on...

Three JavaScript methods to solve the Joseph ring problem

Table of contents Overview Problem Description Ci...

Basic syntax of MySQL index

An index is a sorted data structure! The fields t...

How to improve MySQL Limit query performance

In MySQL database operations, we always hope to a...

MySQL 8.0.20 installation tutorial and detailed tutorial on installation issues

Original address: https://blog.csdn.net/m0_465798...

Vue component organization structure and component registration details

Table of contents 1. Component Organization 2. Co...

Detailed explanation of various types of image formats such as JPG, GIF and PNG

Everyone knows that images on web pages are genera...

Pycharm2017 realizes the connection between python3.6 and mysql

This article shares with you how to connect pytho...

How to configure tomcat server for eclipse and IDEA

tomcat server configuration When everyone is lear...

How to get the size of a Linux system directory using the du command

Anyone who has used the Linux system should know ...

Learn about CSS label display mode in one article

Tag type (display mode) HTML tags are generally d...

Detailed explanation of jquery tag selector application example

This article example shares the specific code of ...