Import on demand:Install the plugin First, you need to introduce additional plug-ins: the former ** npm install unplugin-vue-components Configuring the plugin Add configuration in the weapack or vite configuration file // vite.config.ts import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' export default { plugins: [ // ... Components({ resolvers: [ElementPlusResolver()], }), ], } // webpack.config.js const Components = require('unplugin-vue-components/webpack') const { ElementPlusResolver } = require('unplugin-vue-components/resolvers') module.exports = { // ... plugins: [ Components({ resolvers: [ElementPlusResolver()], }), ], } //main.ts import { createApp } from 'vue' import App from './App.vue' import { Edit,Search } from '@element-plus/icons' //Icons need to be imported separately, import icons on demand import { ElButton } from 'element-plus'; //Import on demand const app = createApp(App); //Register component app.component("edit", Edit) app.component("search", Search) app.component('ElButton',ElButton) app.mount('#app'); <template> <h2>Home Page</h2> <el-button type="primary" >Primary button</el-button> <el-button type="success" >Success button</el-button> <el-icon :size="20" :color="'blue'"> <edit /> </el-icon> <el-icon :size="20"> <search></search> </el-icon> </template> <script setup lang="ts"> </script> Global ImportRecommended Additions // tsconfig.json { "compilerOptions": { // ... "types": ["element-plus/global"] } } Install npm install element-plus --save # or yarn add element-plus # Install icon icon dependency library npm install @element-plus/icons # or yarn add @element-plus/icons Global configuration in main.ts file import { createApp } from 'vue' import App from './App.vue' import { store, key } from './store'; //Inject routingimport router from './router'; // Globally import the UI library import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' const app = createApp(App); app.use(store, key); app.use(router); app.use(ElementPlus); app.mount('#app'); Using UI components Use icons, because icons and ordinary UI components are not in the same package, they need to be imported separately //Use <template> directly after importing specific components <el-icon :size="20" :color="'blue'"> <edit /> </el-icon> </template> <script setup lang="ts"> import { Edit } from '@element-plus/icons' </script> Impott the icon library in the main.ts file and register it with app.component(), then you can use it directly in the component, just like using a normal UI library. <template> <h2>Home Page</h2> <el-button type="primary" >Primary button</el-button> <el-button type="success" >Success button</el-button> <el-icon :size="20" :color="'blue'"> <edit /> </el-icon> <el-icon :size="20"> <search></search> </el-icon> </template> <script setup lang="ts"> </script> This is the end of this article about how to implement on-demand import and global import in element-plus. For more relevant content about element-plus on-demand import and global import, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Recommended 20 best free English handwriting fonts
>>: How to use MyCat to implement MySQL master-slave read-write separation in Linux
Introduction to Dockerfile Docker can automatical...
Upgrade process: Original system: CentOS7.3 [root...
This article mainly introduces why v-if and v-for...
Attribute check-strictly The official document pr...
Introduction Use simple jQuery+CSS to create a cus...
General mobile phone style: @media all and (orien...
Table of contents cache Cache location classifica...
1. Enter the virtualization vcenter, log in with ...
Preface I recently used :first-child in a project...
During the development process, I often encounter...
When we use the MySQL service, under normal circu...
Table of contents Zabbix custom monitoring nginx ...
It has to be said that a web designer is a general...
500 (Internal Server Error) The server encountere...
Table of contents Preface keep-avlive hook functi...