因为太简单没什么好讲的,就直接上代码了,效果如图
e-switch
<template>
<div :class="['e__switch',{'e_is-checked':value}]">
<span class="e__switch-core" @click="toggle"></span>
</div>
</template>
<script>
export default {
name: 'e-switch',
props:['value'],
methods:{
toggle(){
this.$emit('change',!this.value);
this.$emit('input',!this.value);
}
}
}
</script>
<style>
.e__switch {
display: inline-flex;
align-items: center;
position: relative;
font-size: 14px;
line-height: 20px;
height: 20px;
vertical-align: middle;
cursor: pointer;
}
.e__switch>input {
position: absolute;
width: 0;
height: 0;
opacity: 0;
margin: 0;
}
.e__switch-core {
margin: 0;
position: relative;
width: 40px;
height: 20px;
border: 1px solid #DCDFE6;
outline: 0;
border-radius: 10px;
box-sizing: border-box;
background: #DCDFE6;
transition: border-color .3s, background-color .3s;
vertical-align: middle;
}
.e__switch-core::after {
content: "";
position: absolute;
top: 1px;
left: 1px;
border-radius: 100%;
transition: all .3s;
width: 16px;
height: 16px;
background-color: #FFF;
}
.e__switch.e_is-checked .e__switch-core {
border-color: #409EFF;
background-color: #409EFF;
}
.e__switch.e_is-checked .e__switch-core::after {
left: 100%;
margin-left: -17px;
}
</style>