<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.common {
height: 40px;
width: 110px;
background-color: #fff;
outline: none;
border: 1px solid #ccc;
cursor: pointer;
border-radius: 10px;
}
.el-button--default:active,
.el-button--default:focus,
.el-button--default:hover {
border: 1px solid #3a8ee6;
color: #3a8ee6;
background-color: #c6e2ff;
}
.el-button--default.is-plain:active,
.el-button--default.is-plain:focus,
.el-button--default.is-plain:hover {
background: #fff;
border-color: #3a8ee6;
color: #3a8ee6;
}
.is-round {
border-radius: 20px;
}
.el-button--primary {
color: #fff;
background-color: #409eff;
border-color: #409eff;
}
.el-button--primary:focus,
.el-button--primary:hover,
.el-button--primary:active {
background: #66b1ff;
border-color: #66b1ff;
color: #fff;
}
.el-button--primary.is-plain {
color: #409eff;
background: #ecf5ff;
border-color: #b3d8ff;
}
.el-button--primary.is-plain:active,
.el-button--primary.is-plain:focus,
.el-button--primary.is-plain:hover {
background: #66b1ff;
border-color: #66b1ff;
color: #fff;
}
.el-button--success {
color: #fff;
background-color: #5daf34;
border-color: #5daf34;
}
.el-button--success:focus,
.el-button--success:hover,
.el-button--success:active {
background: #67c23a;
border-color: #67c23a;
color: #fff;
}
.el-button--success.is-plain {
color: #67c23a;
background: #f0f9eb;
border-color: #c2e7b0;
}
.el-button--success.is-plain:active,
.el-button--success.is-plain:focus,
.el-button--success.is-plain:hover {
background: #67c23a;
border-color: #67c23a;
color: #fff;
}
.el-button--info {
color: #fff;
background-color: #909399;
border-color: #909399;
}
.el-button--info:focus,
.el-button--info:hover,
.el-button--info:active {
background: #82848a;
border-color: #82848a;
color: #fff;
}
.el-button--info.is-plain {
color: #909399;
background: #f4f4f5;
border-color: #d3d4d6;
}
.el-button--info.is-plain:active,
.el-button--info.is-plain:focus,
.el-button--info.is-plain:hover {
background: #82848a;
border-color: #82848a;
color: #fff;
}
.el-button--warning {
color: #fff;
background-color: #e6a23c;
border-color: #e6a23c;
}
.el-button--warning:focus,
.el-button--warning:hover,
.el-button--warning:active {
background: #cf9236;
border-color: #cf9236;
color: #fff;
}
.el-button--warning.is-plain {
color: #e6a23c;
background: #fdf6ec;
border-color: #f5dab1;
}
.el-button--warning.is-plain:active,
.el-button--warning.is-plain:focus,
.el-button--warning.is-plain:hover {
background: #cf9236;
border-color: #cf9236;
color: #fff;
}
.top,
.middle,
.middle2 {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="app">
<h3>只带type属性</h3>
<div class="top">
<!-- 只带type属性的样式 -->
<el-button>
Top center
</el-button>
<el-button type="primary">
Top center
</el-button>
<el-button type="success">
Top center
</el-button>
<el-button type="info">
Top center
</el-button>
<el-button type="warning">
Top center
</el-button>
</div>
<h3>带type、primary属性</h3>
<div class="middle">
<!-- 带type、primary属性 -->
<el-button plain>
Top center
</el-button>
<el-button type="primary" plain>
Top center
</el-button>
<el-button type="success" plain>
Top center
</el-button>
<el-button type="info" plain>
Top center
</el-button>
<el-button type="warning" plain>
Top center
</el-button>
</div>
<h3>带type、primary、round属性</h3>
<div class="middle2">
<!-- 带type、primary、round属性-->
<el-button plain round>
Top center
</el-button>
<el-button type="primary" plain round>
Top center
</el-button>
<el-button type="success" plain round>
Top center
</el-button>
<el-button type="info" plain round>
Top center
</el-button>
<el-button type="warning" plain round>
Top center
</el-button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
Vue.component('el-button', {
props: {
type: {
type: String
},
plain: {
type: Boolean
},
round: Boolean
},
data() {
return {
classArr: ['common']
}
},
beforeMount() {
console.log(this.plain)
if (this.type) {
this.round
? this.classArr.push('is-round')
: this.classArr.push('el-button--' + this.type)
this.classArr.push('el-button--' + this.type)
if (this.plain) {
this.classArr.push('el-button--' + this.type, 'is-plain')
} else {
this.classArr.push('el-button--' + this.type)
}
} else {
this.round
? this.classArr.push('is-round')
: this.classArr.push('el-button--' + this.type)
if (this.plain) {
this.classArr.push('el-button--default', 'is-plain')
} else {
this.classArr.push('el-button--default')
}
}
},
template: `
<div>
<button :class='classArr'>
<slot></slot>
</button>
</div>
`
})
new Vue({
el: '#app'
})
</script>
</body>
</html>
## 效果图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200324160323316.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIwMTI3Mg==,size_16,color_FFFFFF,t_70#pic_center)