vuejs2 - 如何在Vue3项目中添加element-ui(现在叫element-plus)?

标签 vuejs2 vuejs3 element-ui element-plus

我一直在使用“element-ui”,现在转向新版本的 Vue3。 似乎他们发布了一个名为“element-plus”的新版本,但教程没有更新。

import Vue from 'vue';  // not working in Vue3
import ElementUI from 'element-plus';
import 'element-ui/lib/theme-chalk/index.css';
...

Vue.use(ElementUI);  // no "Vue" in Vue3 anymore
...
createApp(App).mount('#app') // the new project creation

https://element-plus.org/#/en-US/component/quickstart

有人成功地做到了并且有效吗?

最佳答案

如果您使用的是 vue 3,则需要从“element-plus/...”文件夹中导入 createApp 和 css。然后你使用导入的 vue 函数实例化你的 app,基本上你将你的主要应用程序组件作为参数传递给该函数:

import { createApp } from 'vue'
import App from './YourMainApp.vue'

import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
    
let app = createApp(App)
app.use(ElementPlus)
    
app.mount('#app')

关于vuejs2 - 如何在Vue3项目中添加element-ui(现在叫element-plus)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64134028/

相关文章:

typescript - 如何修复错误 TS2339 - 'HTMLElement' 上不存在属性

vue-router - 无法读取未定义的 Vue-Router-next 的监听属性

css - vue中的自定义主题datepicker element-ui

vue.js - 使用 element-ui 组件测试 Vue 组件

javascript - v-for 之后的 Vue 指令

vue.js - Vue 3 和组合 API : template refs in v-for loop error : only get proxies

sass - 在样式表中使用 Vue 数据

javascript - 如何在 Element UI Input v2.x 中键入时发出值?

node.js - 在expressjs服务器和vuejs客户端之间使用快速 session

javascript - NuxtJS|在 header 组件中加载组件