Home > Web Front-end > Vue.js > body text

How to use vue3 api automatic import plug-in

WBOY
Release: 2023-05-10 15:25:06
forward
1920 people have browsed it

1. vue3 automatic import

Principle:

  • Before preloading, the plug-in automatically imports on demand Yes, use api and components

  • in this vue file and when writing code, justNo need to import

  • Note that it is not a global import and will not affect the resources

2. Automatic introduction of API

Ⅰ. Comparison before and after use

Before using the plug-in:

Copy after login

After using the plug-in:

Copy after login

Ⅱ. Install third-party software

npm i -D unplugin-auto-import

Ⅲ. Configure third-party software

##vite.config configuration:

import { defineConfig } from "vite"; 
import AutoImport from 'unplugin-auto-import/vite'

export default defineConfig({
  plugins: [
    AutoImport({ imports: ['vue', 'vue-router'] }),
  ]
  //.........
})
Copy after login

is not only followed by vue and routing, but can also be added to the imports array Other third-party components

3. Automatic introduction of components (recommended artifact by You Yuxi)

Ⅰ. Comparison before and after use

Use Before the plug-in:


Copy after login

After using the plug-in: (You can choose to import the folder)


Copy after login

Ⅱ. Install third-party software

npm i -D unplugin-vue-components

You can set up components to be imported on demand, or you can set up UI frameworks to be imported on demand (such as: element plus, Antd... : Set the UI framework to load automatically. Be careful not to import the UI framework into main.js. When packaging at the same time, use as many UI components as you want to package.

The above is the detailed content of How to use vue3 api automatic import plug-in. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!