1. 首先在 Vue3 中安装 Element Plus:
npm i element-plus -S
  1. 在 main.js 中引入 Element Plus:
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'

createApp(App).use(ElementPlus).mount('#app')
  1. 在组件中使用 Element Plus 的组件,例如 Button:
<template>
  <div>
    <el-button>默认样式</el-button>
    <el-button type="primary">Primary 样式</el-button>
  </div>
</template>
  1. 切换样式

在 Element Plus 官网中提供了多种主题样式,可以根据需求选择不同的主题样式。例如,如果要使用 Element Plus 的紫色主题,可以在 main.js 中引入 'element-plus/lib/theme-chalk/purple/index.css':

import 'element-plus/lib/theme-chalk/purple/index.css'

如果想要切换回默认主题,可以引入 'element-plus/lib/theme-chalk/index.css':

import 'element-plus/lib/theme-chalk/index.css'
  1. 自定义主题

如果想要自定义主题,可以使用 Element Plus 官网提供的在线主题生成器(https://element-plus.gitee.io/#/zh-CN/component/custom-theme)。根据需要调整主题颜色、字体、边框等属性,然后下载生成的主题文件,替换掉项目中的 'element-plus/lib/theme-chalk' 目录下的相应文件即可。

vue3+elementplus切换样式怎么做

原文地址: https://www.cveoy.top/t/topic/9ar 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录