Vue中select 标签自定义样式

需求原因:我在vue开发中,也会习惯使用各种UI库,但让人难受的是,提供的UI组件的样式难以覆盖,比如我要用的select,我的界面风格是深蓝色的,它的白色背景都不符合需求,要跑到element-plus的样式文件去修改。

=》之后,我想,这种简单的组件,我完全可以自己手写,好处可以让我更好的掌握select本身,消除不确定的部分。

=》以后,可以直接拿来当组件使用

下面就是自己修改出来的样式截图

<template> 
 <select v-model="selectId" class="select-box">
    <option v-for="item in options" :key="item.id" :value="item.id">
      {{ item.name }}
    </option>
  </select>
</template>

<script setup>
import {ref, reactive} from 'vue';

let selectId = ref(1);    //默认选择id为1的选项
let options = reactive([  //数据
  {
    id:1,
    name:"张三"
  },
  {
    id:2,
    name:"李四"
  },
  {
    id:3,
    name:"玄策"
  }
]);
</script>

<style scope lang="scss">
.select-box {
  width: 1.8rem; /*设置宽度确保内容 和 下拉icon的距离*/
  padding-top: 0.06rem;
  padding-bottom: 0.06rem;
  padding-left: 0.07rem;
  background: transparent;
  border: none;
  font-size: 0.15rem;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: #ffc000;
  /*清除select聚焦时候的边框颜色*/
  outline: none;
  option {
    background: #06175b;
    border: none;
  }
}
</style>

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tengyuxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值