在vue3项目中按需引入element-plus组件,直接引入会发现默认是英文,这里将会教你如何改为中文,实现自动导入,并修改默认样式
element-ui
vue3-中文文档

  1. 下载element-plus,在vue3和vue2项目中下载还是有区别的
// vue3
npm install element-plus -S
// vue2
npm i element-ui -S
  1. 实现中文组件
<template>
	<el-config-provider :locale="locale">
	  <router-view></router-view>
	</el-config-provider>
</template>

import zhCn from 'element-plus/lib/locale/lang/zh-cn'

// 在setup中定义变量,将zhCn挂载到最外层div上,默认引入的组件将会是中文
setup() {
  return {
    locale: zhCn,
  }
}
  1. 自动引入element组件,在vue-config.js文件中配置,使用到哪个组件就加载哪个组件,通过修改element全局css变量的形式调整组件样式
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')

module.exports = {
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver({
          importStyle: "sass"
        })],
      }),
      Components({
        resolvers: [ElementPlusResolver({
          importStyle: "sass"
        })],
      }),
    ],
  },
  css: {
    loaderOptions: {
      scss: {
      	// 这里是修改默认样式的scss文件
        additionalData: `@use "@/styles/element/index.scss" as *;`,
      },
    },
  }
}
  1. 这里是我修改的scss的样式,可根据自身需求进行修改

$normal-bg: rgba(127, 232, 234, 0.2);
$normal-text: #80e9ea;
$base-color: '#efefef';
$base-bg: '#000';
$base: 'transparent';
@forward 'element-plus/theme-chalk/src/common/var.scss' with (
  $colors: (
    'primary': (
      'base': $normal-text,
    ),
    'success': (
      'base': #ffc0cb,
    ),
    'warning': (
      'base': #e6a23c,
    ),
    'danger': (
      'base': #f56c6c,
    ),
    'error': (
      'base': #f56c6c,
    ),
    'info': (
      'base': #909399,
    ),
  ),
  $bg-color: (
    'overlay': $normal-bg,
  ),
  $text-color: (
    'primary': $base-color,
    'regular': $base-color,
    'placeholder': $normal-text,
  ),
  $border-color: (
    'light': $base,
  ),
  $fill-color: (
    'light': $normal-bg
  ),
  $table: (
    'header-bg-color': $normal-bg,
    'header-text-color': $normal-text
  ),
  $pagination: (
    'bg-color': $base
  ),
  $input: (
    'text-color': $normal-text
  ),
  $select: (
    'border-color-hover': $normal-bg,
  ),
  $select-option: (
    'hover-background': $normal-bg
  ),
  $datepicker: (
    'icon-color': $normal-text,
    'border-color': $base
  ),
  $button: (
    'hover-bg-color': $normal-bg,
  )
)

Logo

前往低代码交流专区

更多推荐