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

Introduction to building a DNS server under centos7

Table of contents 1. Project environment: 2: DNS ...

Do you know all 24 methods of JavaScript loop traversal?

Table of contents Preface 1. Array traversal meth...

Detailed explanation of Mysql self-join query example

This article describes the Mysql self-join query....

One sql statement completes MySQL deduplication and keeps one

A few days ago, when I was working on a requireme...

Implementation of mysql8.0.11 data directory migration

The default storage directory of mysql is /var/li...

jQuery implements shopping cart function

This article example shares the specific code of ...

Centos7 installation and configuration of Mysql5.7

Step 1: Get the MySQL YUM source Go to the MySQL ...

React sample code to implement login form

As a Vue user, it's time to expand React. Fro...

How to implement form validation in Vue

1. Installation and use First, install it in your...

WeChat applet custom tabBar step record

Table of contents 1. Introduction 2. Customize ta...

MySQL Order By Multi-Field Sorting Rules Code Example

Say it in advance On a whim, I want to know what ...

Docker Stack deployment method steps for web cluster

Docker is becoming more and more mature and its f...