创建下拉框组件 Select.vue

<template>
<div class="selects">
<div
:class="{selects0show: !isshow,selects0hade: isshow}"
class="selects0"
@click="isshow=!isshow"
>
<p ref="mybox">请选择</p>
<img src="@/assets/home/z_x_jt.png" alt srcset />
</div>
<div ref="myselect" :class="{show: !isshow,hade: isshow}" class="sel">
<div
@click="cutValue(1)"
ref="mybox1"
:class="{borders:num ==1}"
:style="{display: num >=1?'block':'none'}"
>{{selects1}}</div>
<div
@click="cutValue(2)"
ref="mybox2"
:class="{borders:num ==2}"
:style="{display: num >=2?'block':'none'}"
>{{selects2}}</div>
<div
@click="cutValue(3)"
ref="mybox3"
:class="{borders:num ==3}"
:style="{display: num >=3?'block':'none'}"
>{{selects3}}</div>
<div
@click="cutValue(4)"
ref="mybox4"
:class="{borders:num ==4}"
:style="{display: num >=4?'block':'none'}"
>{{selects4}}</div>
<div
@click="cutValue(5)"
ref="mybox5"
:class="{borders:num ==5}"
:style="{display: num >=5?'block':'none'}"
>{{selects5}}</div>
</div>
</div>
</template> <script>
export default {
props: {
num: String, //显示多少个下拉框
selects1: String, //列表里的文字
selects2: String,
selects3: String,
selects4: String,
selects5: String
},
data() {
return {
isshow: true //控制下拉框显示及隐藏
};
},
methods: {
//点击换文字的方法
cutValue(val) {
let _this = this
cutfun(val)
_this.isshow = true;
function cutfun(val){
if (val == 1) {
_this.$refs.mybox.innerText = _this.$refs.mybox1.innerText;
} else if(val == 2){
_this.$refs.mybox.innerText = _this.$refs.mybox2.innerText;
} else if(val == 3){
_this.$refs.mybox.innerText = _this.$refs.mybox3.innerText;
}else if(val == 4){
_this.$refs.mybox.innerText = _this.$refs.mybox4.innerText;
}else if(val == 5){
_this.$refs.mybox.innerText = _this.$refs.mybox5.innerText;
}
_this.$emit("va", val, _this.$refs.mybox.innerText);
}
}
}
};
</script> <style lang="less" scoped>
//显示下拉框
.show {
display: block;
}
//隐藏下拉框
.hade {
display: none;
}
//点击时改变选择框的边框颜色
.selects0show {
border: 1px solid #01be6e;
}
//恢复边框颜色
.selects0hade {
border: 1px solid #e4e4e4;
}
//最后一个下拉框底部加边框
.borders {
border-bottom: 1px solid #01be6e !important;
} //倒三角
.traing{
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 10px solid #666666;
}
.selects {
width: 100%;
height: 100%;
.selects0 {
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
p {
line-height: 100%;
display: inline;
color: #666666;
font-size: 15px;
padding-left: 10px;
}
img {
margin-right: 10px;
transform: translateY(-2px);
}
}
.sel {
width: 100%;
height: 100%;
div {
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
line-height: 35px;
border: 1px solid #01be6e;
border-top: none;
padding-left: 10px;
border-bottom: none;
background: white;
}
div:hover {
background: #01be6e;
color: white;
}
.selects0:hover {
background: white;
}
}
}
</style>

使用下拉框组件

//注:下拉框组件的宽高依赖于组件的父盒子
<template>
<div class="t_selects">
<!-- 使用下拉框组件 -->
<Myselects
//@va是子组件传给父组件的事件 有两个参数(当前点击下拉框的索引,当前点击下拉框里面的文字)
@va="sunValue"
//num是指定下拉框的个数 最多为5个
num="3"
//selects1-selects5 是自定义下拉框1-5里面的内容
:selects1="selects1"
:selects2="selects2"
:selects3="selects3"
></Myselects>
</div>
</template> <script>
import Selects from "@/components/Selects";
export default {
data() {
return {
selects1: "列表1",
selects2: "列表2",
selects3: "列表3",
}
}
components: {
Myselects: Selects
},
methods: {
//拿到子组件下拉框里面的索引及内容 参数(当前点击下拉框的索引,当前点击下拉框里面的文字)
sunValue(index,val) {
console.log(index,val);
}
}
}
</script>
//定义父盒子的宽高
<style>
.t_selects {
width: 300;
height: 35px;
z-index: 1000;
}
</style>
效果图:

  图片素材

不喜勿喷

vue自定义下拉框组件的更多相关文章

  1. Combo( 自定义下拉框) 组件

    本节课重点了解 EasyUI 中 Combo(自定义下拉框)组件的使用方法,这个组件依赖于ValidateBox(验证框)组件 一. 加载方式自定义下拉框不能通过标签的方式进行创建.<input ...

  2. 第二百一十二节,jQuery EasyUI,Combo(自定义下拉框)组件

    jQuery EasyUI,Combo(自定义下拉框)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 Combo(自定义下拉框)组件的使用方 ...

  3. 第二百二十四节,jQuery EasyUI,ComboGrid(数据表格下拉框)组件

    jQuery EasyUI,ComboGrid(数据表格下拉框)组件 学习要点: 1.加载方式 2.属性列表 3.方法列表 本节课重点了解 EasyUI 中 ComboGrid(数据表格下拉框)组件的 ...

  4. 自绘制HT For Web ComboBox下拉框组件

    传统的HTML5的下拉框select只能实现简单的文字下拉列表,而HTforWeb通用组件中ComboBox不仅能够实现传统HTML5下拉框效果,而且可以在文本框和下拉列表中添加自定义的小图标,让整个 ...

  5. easyui源码翻译1.32--Combo(自定义下拉框)

    前言 扩展自$.fn.validatebox.defaults.使用$.fn.combo.defaults重写默认值对象.下载该插件翻译源码 自定义下拉框显示一个可编辑的文本框和下拉面板在html页面 ...

  6. ComboTree( 树型下拉框) 组件

    本节课重点了解EasyUI中Tree(树)组件的使用方法, 这个组件依赖于Combo(下拉框)和 Tree(树)组件.一. 加载方式//class 加载方式<select id="cc ...

  7. 第二百二十七节,jQuery EasyUI,ComboTree(树型下拉框)组件

    jQuery EasyUI,ComboTree(树型下拉框)组件 学习要点: 1.加载方式 2.属性列表 3.方法列表 本节课重点了解EasyUI中ComboTree(树型下拉框)组件的使用方法,这个 ...

  8. jquery美化select,自定义下拉框样式

    select默认的样式比较丑,有些应用需要美化select,在网上找到一个很好的美化样式效果,本人很喜欢,在这里分享一下. <!DOCTYPE html PUBLIC "-//W3C/ ...

  9. 关于safari上的select宽高问题小技,自定义下拉框

    之前一直用windows做开发,最近换了个mac,在几经折腾之下,安装完了各种开发工具,IDE等,然后欣然打开自己正在开发的网站.突然发现mac上所有的下拉框都变了,都是默认样式,无论padding, ...

随机推荐

  1. 前端网(http://www.qdfuns.com/)不能访问了

    前端网(http://www.qdfuns.com/)不能访问了 之前写的一些知识点也找不到了,有点难受.... 这说明知识点还是放在本地电脑稳一点,多备份,云端时刻在变化... 希望博客园别也用着用 ...

  2. Python修改元组

    Python修改元组:元组中的元素值是不允许修改的,当创建好的时候就是固定不变的.所谓的修改其实是指创建一个新的元组,只是该元组可能是比原来的元组多一个元素或者少一个元素,然后使用新创建好的元组代替原 ...

  3. 使用pdf.js实现前端页面预览pdf文档,解决了跨域请求

    pdf.js主要包含两个库文件,一个pdf.js和一个pdf.worker.js,,一个负责API解析,一个负责核心解析 官网地址:http://mozilla.github.io/pdf.js/ 下 ...

  4. CF R 635 div2 1337D Xenia and Colorful Gems 贪心 二分 双指针

    LINK:Xenia and Colorful Gems 考试的时候没想到一个很好的做法. 赛后也有一个想法. 可以考虑答案的样子 x,y,z 可以发现 一共有 x<=y<=z,z< ...

  5. ssm框架中applicationContext.xml文件中配置别名

    在applicationContext.xml中配置如下: 通过以下property标签中给定name属性value属性及对应的值,来将domain包下所有实体类设置别名. 在xxxDao.xml中 ...

  6. Python环境搭建、python项目以docker镜像方式部署到Linux

    Python环境搭建.python项目以docker镜像方式部署到Linux 本文的项目是用Python写的,记录了生成docker镜像,然后整个项目在Linux跑起来的过程: 原文链接:https: ...

  7. 静态集成腾讯TBS X5内核WebView,从微信提取新版30M浏览器内核打包进apk

    目录 前情提要 第一步:下载老版本SDK得到jar 获取SDK 集成SDK 步骤二.下载提取最新TBS X5内核 方法1:从微信中提取 方法2:App内内访问tbs调试页安装新内核 步骤三.集成内核到 ...

  8. Java 多态 接口继承等学习笔记

    Super关键字 1.子类可以调用父类声明的构造方法 : 语法:在子类的构造方法中使用super关键字  super(参数列表) 2.操作被隐藏的成员变量(子类的成员变量和父类的成员变量重名的说法)和 ...

  9. 微信小程序 progress 进度条 内部圆角及内部条渐变色

    微信小程序progress进度条内部圆角及渐变色 <view class="progress-box"> <progress percent="80&q ...

  10. GhostNet:more features from cheap operation