• vue select选择下拉组织树,解决不出现横向滚动条


    背景:由于项目需求需要使用下拉选择框的组织架构树

    实现代码如下:

    1. "18">
    2. "所属组织:" prop="groupName">
    3. "dataForm.groupName" placeholder="请选择" >
    4. "select-tree">
    5. "groupList" :props="defaultProps" @node-click="handleNodeClick" :filter-node-method="filterNode" ref="tree">
    1. data() {
    2. return {
    3. defaultProps: {
    4. children: 'childList',
    5. label: 'groupName',
    6. id:'id'
    7. },
    8. filterText: '',
    9. // filters: {
    10. // deptName: '',
    11. // deptCode: ''
    12. // },
    13. dataForm:{
    14. groupName: '',
    15. id: ''
    16. },
    17. rules: {
    18. groupName: [{ required: true,message:'请选择组织', trigger: 'blur' }],
    19. },
    20. };
    21. },
    22. watch:{
    23. filterText(val) {
    24. this.$refs.tree.filter(val);
    25. }
    26. },
    27. methods: {
    28. //关键字过滤
    29. filterNode(value, data) {
    30. if (!value) return true;
    31. return data.label.indexOf(value) !== -1;
    32. },
    33. //点击选择
    34. handleNodeClick(data) {
    35. let self = this;
    36. self.dataForm.groupName = data.groupName
    37. self.dataForm.id = data.id
    38. },
    39. }

    注意:groupList为组织结构的数据,具体情况结合自己的项目。

    css:

    1. ::v-deep.select-tree{
    2. width: 240px;
    3. height: 100%;
    4. .el-tree {
    5. background: #FFFFFF;
    6. //el-tree组件中class名为el-tree-node的div是块级元素,需要把它变为inline-block才出现滚动条,同时注意每一个节点占一行,
    7. //由于选择框组织树需要添加el-tree-node__children 如下所示
    8. .el-tree>.el-tree-node {
    9. display: inline-block;
    10. min-width: 100%;
    11. }
    12. .el-tree-node__children{
    13. overflow: visible!important;
    14. }
    15. // 选择框改成灰色
    16. // .el-checkbox__inner {
    17. // background-color: #edf2fc;
    18. // }
    19. // 人员树高度
    20. .el-tree-node__content {
    21. height: 31px;
    22. display: block!important;
    23. }
    24. // 人员树内容鼠标悬浮颜色
    25. .el-tree-node__content:hover{
    26. // background-color: #FFEFED !important;
    27. background-color: #FFFFFF !important;
    28. width: 100% !important;
    29. }
    30. // 人员树内容鼠标点击背景颜色
    31. .el-tree-node:focus > .el-tree-node__content {
    32. // background-color: #FFEFED !important;
    33. background-color: #FFFFFF !important;
    34. }
    35. // 箭头颜色更改
    36. .el-tree-node__expand-icon {
    37. color:#A4AEBB;
    38. font-size: 19*0.87px;
    39. }
    40. //人员树字体大小
    41. .el-tree-node__label {
    42. font-size: 19*0.87px;
    43. }
    44. }
    45. }

    其中,添加了

    .el-tree-node__children{

            overflow: visible!important;

        }

    才正常出现横向滚动条

    效果图如下:

  • 相关阅读:
    C语言:文件操作(2)
    c++ VS2019中使用Log4cplus打印日志最新介绍、详细编译过程及使用
    GIt后悔药:还原提交的操作(谨慎操作)
    采用WPF开发第二版OFD阅读器,持续完善中,敬请期待!
    Java CountDownLatch 学习总结
    时间戳权限
    如何使用ArkUI从0-1写一个开发购物应用程序(下)
    FlexRAN BBU Pool 设计的思考:为什么常见的设计是三维度的,以及类比,机器理解
    PCL 滤波采样(二)——直通滤波
    【LeetCode每日一题】——561.数组拆分
  • 原文地址:https://blog.csdn.net/weixin_46567616/article/details/134669034