ElementUI 修改默认样式

ElementUI 是一套ui组件库,在项目开发中,难免遇到要需求修改其默认样式的情况,本文就vue 框架介绍几种修改 ElementUI 默认样式的办法。

1、安装

  • 安装
npm i element-ui -S
  • 使用
import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
  
Vue.use(ElementUI);
  
new Vue({
 el: '#app',
 render: h => h(App)
});

2、修改样式

一、内嵌法修改样式

通过 :style 修改,用于局部组件块

<el-button :style="selfstyle">默认按钮</el-button>
<script>
 export default {
 data() {
  return {
  selfstyle: {
   color: "white",
   marginTop: "10px",
   width: "100px",
   backgroundColor: "cadetblue"
  }
  };
 }
 }
</script>

二、class引用修改样式

通过 :class 修改,用于局部组件块

<el-button :class="[selfbutton]">默认按钮</el-button>
<script>
 export default {
 data() {
  return {
  selfbutton: "self-button"
  };
 }
 }
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
 .self-button {
 color: white;
 margin-top: 10px;
 width: 100px;
 background-Color: cadetblue;
 }
</style>

三、import导入修改样式

通过 import 导入样式文件,若在 main.js 中导入css 则表示全局引用。既可以用于局部组件块也可以用于全局组件

<el-button>和下面的el-button效果一样</el-button>
<el-button :class="[selfbutton]">默认按钮</el-button>
<script>
 import './button.css'
 export default {
 }
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
</style>
/* button.css */
.el-button {
 color: white;
 margin-top: 10px;
 width: 100px;
 background-Color: cadetblue;
}
  
.self-button {
 color: white;
 margin-top: 10px;
 width: 100px;
 background-Color: cadetblue;
}
  
.self-button:hover {
 color: black;
 background-Color: whitesmoke;
}

文章链接: https://www.jb51.net/article/192026.htm

posted @ 2021-04-23 16:30  直角漫步  阅读(954)  评论(0编辑  收藏  举报