el-select范围选择框

这篇具有很好参考价值的文章主要介绍了el-select范围选择框。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、html

<el-select
v-model="searchForm.hour"
:class="searchForm.hour?.length>1?'edit-tag-hour':'keep-tag-hour'"
filterable
multiple
clearable
:multiple-limit="2"
@remove-tag="removeChange"
@change="hourChange"
>
<el-option v-for="item in hourList" :key="item.value" class="ad-hour-bg" :label="item.label" :value="item.value" @mouseover.native="handleMouseOver(index)" />
</el-select>

2、js

    handleMouseOver(index) {
      if (this.searchForm.hour?.length === 1) {
        const arrIndex = [this.searchForm.hour[0], index].sort((x, y) => x - y)
        const elements = document.querySelectorAll('.ad-hour-bg')
        elements.forEach((element, index) => {
          if (index > arrIndex[0] && index < arrIndex[1]) {
            element.style.backgroundColor = '#F2F6FC'
            element.style.color = '#C0C4CC'
          } else if (index === arrIndex[1]) {
            element.style.backgroundColor = '#1177ff'
            element.style.color = '#FFF'
          } else if (index !== arrIndex[0]) {
            element.style.backgroundColor = ''
            element.style.color = '#606266'
          }
        })
      }
    },   
 removeChange(value) {
      if (this.searchForm.hour?.length > 0) {
        const elements = document.querySelectorAll('.ad-hour-bg')
        elements.forEach((element, index) => {
          if (index === this.searchForm.hour[0]) {
            element.style.backgroundColor = '#FFF'
            element.style.color = '#606266'
          }
        })
        this.searchForm.hour = null
      }
    },
    hourChange(value) {
      const elements = document.querySelectorAll('.ad-hour-bg')
      if (value?.length > 1) {
        value.sort((x, y) => x - y)
        this.$nextTick(() => {
          const parentElement = document.querySelector('.edit-tag-hour')
          if (parentElement) {
            const bbElements = parentElement.querySelectorAll('.el-select__tags-text')
            if (bbElements.length > 0) {
              const firstBbElement = bbElements[0]
              firstBbElement.textContent = `${firstBbElement.textContent} - `
            }
          }
        })
        elements.forEach((element, index) => {
          if (index > value[0] && index < value[1]) {
            element.style.backgroundColor = '#F2F6FC'
          } else if (index === value[0] || index === value[1]) {
            element.style.backgroundColor = '#1177ff'
            element.style.color = '#FFF'
          } else {
            element.style.color = '#C0C4CC'
          }
        })
      } else {
        elements.forEach((element, index) => {
          if (index === value[0]) {
            element.style.backgroundColor = '#1177ff'
            element.style.color = '#FFF'
          } else {
            element.style.backgroundColor = ''
            element.style.color = '#606266'
          }
        })
        this.$nextTick(() => {
          const parentElement = document.querySelector('.keep-tag-hour')
          if (parentElement) {
            const bbElements = parentElement.querySelectorAll('.el-select__tags-text')
            const firstBbElement = bbElements[0]
            firstBbElement.textContent = firstBbElement.textContent.replace('-', '')
          }
        })
      }
    },

3、 css

  .edit-tag-hour {
    .el-tag:nth-child(1) {
      border-right: 0;
      border-radius: 4px 0 0 4px;
      padding-right: 0;
      .el-tag__close {
        display: none;
      }
    }
    .el-tag:nth-child(2) {
      margin-left: 0;
      border-left: 0;
      border-radius: 0 4px 4px 0;
    }
  }

效果图 

el-select范围选择框,vue.js,javascript,前端

仅供参考,具体的实现可能根据自己的需要修改 ,仅供参考!仅供参考!仅供参考!文章来源地址https://www.toymoban.com/news/detail-681808.html

到了这里,关于el-select范围选择框的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • element el-select下拉框选择失效

    2023.1.11今天我学习了使用element el-select组件下拉框选择数据失效的原因以及解决办法。 如图:   当我已经选择启用状态的时候,然后点击停用状态没反应。 是因为在配置表单的过程中,重复使用了这个字段。 如: 就是在表单中重复使用了status这个字段,然后导致选择失效。

    2024年02月16日
    浏览(29)
  • vue2 - 详细介绍element UI中在el-select嵌套el-tree树形控件实现下拉选择树型结构数据的效果实例(组件封装)

    在项目上常用使用到 el-select 和 el-tree 组合实现,记录下两者结合的实现过程。(代码以及注释清晰明了,代码直接使用即可) 要求根据项目接口提供的数据,el-tree 里的数据是一次性返回来的,点击最后一层级时,请求接口,在点击层级下方追加数据追加的数据要显示勾

    2024年04月15日
    浏览(43)
  • VUE element-ui 使用Screefull 页面全屏时el-select下拉菜单不显示(下拉框不显示无法选择)问题解决

    问题原因:elemrnt-ui会默认将弹出框插入至 body 元素;当设置了某个元素全屏时,会遮挡住原来的select下拉数据。

    2024年02月14日
    浏览(41)
  • elementUI --- el-select 下拉框 日历 级联选择

    element UI 组件库中的 select 选择器 中下拉列表的样式,在页面渲染的时候,总是渲染为仅次于body级别的div ,这样子覆盖样子会影响全局其他的select选择器下拉框样式,试图通过给el-select加父标签来覆盖,然而并没有卵用。 控制台看到的渲染结果: 解决方法: 通过 popper-cla

    2024年02月15日
    浏览(37)
  • 【elementUI】el-select选择框位置错位、偏移bug

    在el-select组件中,可能会由于option选项过多而导致下拉框位置错乱、偏移的情况,我个人试验大概是在5-6个option以上时,该bug就会出现。 这个时候需要手动为下拉框设置: popper-append-to-body=\\\"false\\\" 属性,并设置以下CSS样式解决问题:

    2024年02月15日
    浏览(34)
  • el-select与el-tree结合使用,实现select框下拉使用树形结构选择数据

    使用el-select与el-tree,实现如下效果, 代码如下:  注意点:搜索input框的代码一点放在option上面,不要放在option里面,否则一点击搜索框,下拉框就会收起来,不能使用。

    2024年02月13日
    浏览(37)
  • el-select数据过多的解决(纯前端)

    el-select数据过多这个问题应该很多人都遇到过,在生产环境中数据几百、几千条是比较常见的。当数据过多时,就会造成浏览器卡顿,如果客户电脑性能不行,浏览器直接卡死也有可能。 先说一下现在项目中遇到的两种解决方案: 添加分页条 这种方案好像有点问题,具体什

    2024年02月09日
    浏览(30)
  • el-select报错:vue.esm.js?5cd5:5105 [Vue warn]: <transition-group> children must be keyed: <ElTag>;无法选中

    目录 一、问题 二、原因及解决方法 三、总结 Tips:嫌麻烦可以直接看总结中有颜色的字体即可! 1. 使用element select控件时有警告(transition-group children must be keyed: ElTag)且无法选中下拉项 vue.esm.js?5cd5:5105 [Vue warn]: transition-group children must be keyed: ElTag found in --- TransitionGroup        

    2024年02月14日
    浏览(30)
  • vue el-select默认值

    情景:在调取接口后渲染数据时需要将选取的select设为默认值,具体案例为调取省份数据后,根据省份获取其对应的城市数据,并将其对应的el-select默认选中该数据的状态 问题:看到网上很多说直接改el-select绑定的v-model的值,这样做就会掉入select框中仅仅是显示相应的文字

    2024年02月13日
    浏览(41)
  • 解决element-ui中的el-select选择器无法显示选中内容的问题

    问题描述: 排查方法: 检查数据控制台是否报错,无报错 检查change是否触发,会触发 最后开始百度,查看文档  官方文档有这么一段话,就是属性一定要挂载到data上,不然无法检测。 最后解决: 排查到我的form表单,在定义表单属性的时候,没有在data中定义该字段。 总结

    2024年01月23日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包