vue 封裝 radio 組件,純css手寫,需修改樣式可自制

zl-radio

<template>
  <input type="radio" 
    class="input_check" 
    :disabled="disabled" 
    :checked="checked"
    @change="change"/>
</template>
<script>
export default {
  data(){
    return{
      // checked: false
    }
  },
  model: {
    prop: 'checked',
    event: 'change'
  },
  methods:{
    change(e){
      this.$emit('change', e.target.checked)
    }
  },
  props:{
    checked:{
      type:Boolean,
      default:false
    },
    disabled:{
      type:Boolean,
      default:false
    }
  }
}
</script>
<style lang="less" scoped>
input[type=radio] {
  width: .4rem;
  height: .4rem;
  -webkit-appearance: none;
  background-color: transparent;
  border: 0;
  outline: 0 !important;
  color: #d8d8d8;
  position: relative;
} 
input[type=radio]:before{
  content: "";
  display:block;
  width: .4rem;
  height: .4rem;
  border: 1px solid #ddd;
  background-color: #fff;
  box-sizing:border-box;  
  border-radius: .4rem;
  position: absolute;
}

input[type=radio]:disabled:before{
  content: "";
  display:block;
  width: .4rem;
  height: .4rem;
  border: 1px solid #333;
  background-color: #333;
  box-sizing:border-box;  
  border-radius: .4rem;
  position: absolute;
}
input[type=radio]:checked:before{
  content: "";
  display:block;
  width: .4rem;
  height: .4rem;
  border: 1px solid #D2A47E;
  background-color: #D2A47E;
  box-sizing:border-box;  
  border-radius: .4rem;
  position: absolute;
}
input[type=radio]:checked:after{
  content: "";
  display:block;
  width: .15rem;
  height: .3rem;
  border-left: .06rem solid #fff;
  border-top: .06rem solid #fff;
  border-radius:  .06rem;
  box-sizing:border-box; 
  position: absolute;
  transform: rotate(-135deg) translate(-70%, 25%);
}
</style>

未選狀態(tài)
選中狀態(tài)

更多詳細(xì)知識介紹請訪問我的個人主頁

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容