当前位置: 首页 > news >正文

vue3配置element-ui的使用

今天阐述一下如何在vue中进行配置使用element-ui;

一,配置下载Element

1.首页在电脑上下载好vue,以及npm,可以去相关的官方进行下载。
2.进行配置命令

npm install element-plus --save

如报错:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: vue3_cli_default@0.0.0
npm error Found: vue@3.5.13
npm error node_modules/vue
npm error   vue@"^3.2.8" from the root project
npm error
npm error Could not resolve dependency:
npm error peer vue@"^2.5.17" from element-ui@2.15.14
npm error node_modules/element-ui
npm error   element-ui@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /Users/rnd/.npm/_logs/2025-05-12T02_23_38_037Z-eresolve-report.txtnpm error A complete log of this run can be found in: /Users/rnd/.npm/_logs/2025-05-12T02_23_38_037Z-debug-0.log

先删除npm uninstall element-ui,运行:

npm uninstall element-ui

再次运行npm install element-plus --save进行安装element

二:在项目的main.js配置全局

import { createApp } from 'vue'
import App from './App.vue'// 引入 Element Plus 和它的样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'const app = createApp(App)// 使用 Element Plus 插件
app.use(ElementPlus)app.mount('#app')

or或者

import App from './App'// 引入 Element Plus 和样式
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({...App
})
app.$mount()
// #endif// #ifdef VUE3
import {createSSRApp
} from 'vue'
export function createApp() {const app = createSSRApp(App)// 使用 Element Plus 插件app.use(ElementPlus)return {app}
}
// #endif

三:使用与调用Element-UI组件

index.vue中:

<template><view class="content"><el-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949"></el-switch></view>
</template><script>export default {data() {return {value: true}},onLoad() {},methods: {}}
</script><style>.content {display: flex;flex-direction: column;align-items: center;justify-content: center;}
</style>

或者在app.vue中:

<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
import Time from './components/Time.vue'
</script><template><HelloWorld/><Time/>
</template><style>
#app {font-family: Avenir, Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px;
}
</style>

HelloWorld组件如下:

<template><el-switchv-model="value1"active-text="按月付费"inactive-text="按年付费"></el-switch><el-switchstyle="display: block"v-model="value2"active-color="#13ce66"inactive-color="#ff4949"active-text="按月付费"inactive-text="按年付费"></el-switch>
</template>
<script>export default {data() {return {value1: true,value2: true}}};
</script>

Time组件如下:

<template>
<el-time-selectv-model="value":picker-options="{start: '08:30',step: '00:15',end: '18:30'}"placeholder="选择时间">
</el-time-select>
</template>
<script>export default {data() {return {value: ''};}}
</script>

此时运行,看结果

在这里插入图片描述

大功告成,继续加油!

相关文章:

  • 开启WSL的镜像网络模式
  • 从攻击者角度来看Go1.24的路径遍历攻击防御
  • IEEE出版|2025年算法、软件与网络安全国际学术会议(ASNS2025)
  • 【愚公系列】《Manus极简入门》034-跨文化交流顾问:“文化桥梁使者”
  • 制造业IT管理方法论:柔性变更与数据治理的融合实践
  • 星海智算云平台部署GPT-SoVITS模型教程
  • 电脑端实用软件合集:土拨鼠+Rufus+实时网速监控工具
  • OpenCV进阶操作:光流估计
  • 原生的 XMLHttpRequest 和基于 jQuery 的 $.ajax 方法的异同之处以及使用场景
  • 人工智能浪潮下:如何选择适合你的认证路径?
  • netty 客户端发送消息服务端收到消息无法打印,springBoot配合 lombok使用@Slf4j
  • 辣椒青椒幼苗和杂草检测数据集VOC+YOLO格式706张2类别
  • 《AI大模型应知应会100篇》第59篇:Flowise:无代码搭建大模型应用
  • flutter使用命令生成BinarySize分析图
  • 专题二:二叉树的深度搜索(二叉树剪枝)
  • 《 C++ 点滴漫谈: 三十七 》左值?右值?完美转发?C++ 引用的真相超乎你想象!
  • GB/T 17626.5-2019浪涌抗扰度【研读笔记】
  • IOP|2025第二届机电一体化、机器人与控制系统国际会议(MRCS2025)
  • 在选择合适的实验室铁地板和铸铁试验平板,帮分析​
  • 【机器人】复现 UniGoal 具身导航 | 通用零样本目标导航 CVPR 2025
  • 石家庄推动城市能级与民生福祉并进
  • 不到1小时就能速发证件?央媒曝光健康证办理乱象
  • 2025年两岸关系研讨会在上海开幕
  • 罕见沙尘再度入川,官方:沙尘传输高度达到平流层,远超以往
  • 美联储宣布维持联邦基金利率目标区间不变
  • 数据中心业务今年预增50%,丹佛斯:中国是全球最重要的市场