vue3怎么安装element-ui
时间: 2023-11-19 09:56:40 浏览: 89
在Vue3中,ElementUI已经升级为Element Plus,需要使用unplugin-vue-components和unplugin-auto-import这两款插件来按需引入Element Plus。具体安装方法如下:
1. 首先安装Element Plus:npm install element-plus -S
2. 安装unplugin-vue-components和unplugin-auto-import:npm install -D unplugin-vue-components unplugin-auto-import
3. 在vue.config.js中配置插件:
```javascript
const { defineConfig } = require('vite')
const vue = require('@vitejs/plugin-vue')
const Components = require('unplugin-vue-components/vite')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
module.exports = defineConfig({
plugins: [
vue(),
Components({
resolvers: [ElementPlusResolver()],
}),
],
})
```
4. 在需要使用Element Plus的组件中,按需引入所需组件即可,例如:
```javascript
<template>
<el-button>Click me</el-button>
</template>
<script>
import { defineComponent } from 'vue'
import { ElButton } from 'element-plus'
export default defineComponent({
components: {
ElButton,
},
})
</script>
```
阅读全文