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
Inject axios into Vue import axios from 'axio...
The MySQL server is running with the --skip-grant...
Create a simple Spring boot web project Use the i...
Preface echarts is my most commonly used charting...
Table of contents Start by clicking the input box...
This article shares the specific code for JavaScr...
Simply use CSS to achieve all the effects of corn...
File transfer between Windows and Linux (1) Use W...
First method Alibaba Cloud and Baidu Cloud server...
Table of contents Basic selectors: Level selector...
Table of contents Prerequisites useEffect commitB...
Preface This article mainly shares with you the g...
Most of the commands below need to be entered in ...
Table of contents Background 1. What is dns-prefe...
When configuring nginx reverse proxy, the slashes...