当前位置: 首页 > 知识库问答 >
问题:

vue.js - details、summary树形做成vue版本后,hover效果无法显示?

诸新霁
2023-08-17

目标效果参考:https://segmentfault.com/a/1190000043966941
改成 vue 版本后,鼠标移动到节点上的显示背景效果怎么也不显示了,哪里的问题?

看不懂例子里面 z-index: -1 是怎么显示的,按照正常逻辑,这个伪类绝对定位切zindex等于-1,不应该被挡住了吗?

treeTableItem.vue

<template>    <details>        <summary class="tree-item">            <span>{{ item.name }}</span>        </summary>        <template v-if="item.children">            <treeTableItem v-for="(i, idx) in item.children" :item="i" :key="`level_${item.level}_${idx}`"></treeTableItem>        </template>    </details></template><script>import treeTableItem from './treeTableItem'export default {    name: 'treeTableItem',    components: {        treeTableItem,    },    props: {        item: Object    },    data() {        return {        }    },}</script>

treeTable.vue

<template>    <div class="my-custom-tree" id="tree" ref="treeWrapper">        <treeTableItem v-for="(item, idx) in list" :item="item" :key="`item_${idx}`"></treeTableItem>    </div></template><script>import treeTableItem from './treeTableItem'export default {    name: 'tree-table',    components: {        treeTableItem,    },    mounted() {        this.$refs.treeWrapper.addEventListener('click', function(ev){            if (ev.target.tagName === 'SPAN') {                 ev.preventDefault()            }        })    },    props: {        list: {            type: Array,            default: () => {                return []            }        },    },    data () {        return {        }    },    methods: {    },}</script><style lang="scss" scoped>.my-custom-tree {    flex: 1;    overflow: auto;    padding: 4px 0;    position: relative;}.my-custom-tree{    /deep/summary {        outline: 0;        padding-left: 30px;        list-style: none;        background: repeating-linear-gradient(90deg, #999 0 1px, transparent 0px 2px) 0px 50%/20px 1px no-repeat;    }}.my-custom-tree{    /deep/details:last-child {        background-size: 1px 23px;    }}.my-custom-tree{    ::v-deep >details:not(:last-child)>details:last-child {        background-size: 1px 100%;    }}.my-custom-tree {    /deep/details {        padding-left: 40px;        background: repeating-linear-gradient(#999 0 1px, transparent 0px 2px) 40px 0px/1px 100% no-repeat;        /* background: linear-gradient(#999, #999) 40px 0px/1px 100% no-repeat; */    }}.my-custom-tree{    >details {        background: none;        padding-left: 0;    }}.my-custom-tree{    ::v-deep >details{        >summary {            background: none;        }    }}.my-custom-tree {    /deep/summary {        display: flex;        align-items: center;        height: 46px;        font-size: 14px;        line-height: 22px;        color: rgba(0, 0, 0, 0.85);        cursor: default;    }}.my-custom-tree {    /deep/summary::after {        content: "";        position: absolute;        left: 10px;        right: 10px;        height: 38px;        background: #eef2ff;        background: red;        border-radius: 8px;        z-index: -1;        opacity: 0;        transition: 2s;    }} .my-custom-tree {    /deep/summary:hover::after {        opacity: 1;    }}.my-custom-tree {    /deep/summary:not(:only-child)::before {        content: "";        width: 14px;        height: 14px;        flex-shrink: 0;        margin-right: 8px;        border: 1px solid #999;        background: linear-gradient(#999, #999) 50%/1px 10px no-repeat,            linear-gradient(#999, #999) 50%/10px 1px no-repeat;    }}.my-custom-tree {    /deep/details[open]>summary::before {        background: linear-gradient(#999, #999) 50%/10px 1px no-repeat;    }}.my-custom-tree{    /deep/summary span {        line-height: 46px;    }}.my-custom-tree {    /deep/summary::before {        position: relative;        z-index: 2;        cursor: pointer    }}.my-custom-tree {    /deep/summary span::before {        content: '';        position: absolute;        left: 0;        right: 0;        height: 46px;    }}</style>

使用页面代码:

const treeData = [    {        "id": 2,        "name": "项目1",        "parentId": 1,        "fileCount": 14,        "children": [            {                "id": 8,                "name": "文件夹",                "parentId": 2,                "fileCount": 12,                "children": [                    {                        "id": 137,                        "name": "sdd",                        "parentId": 8,                        "fileCount": 0                    }                ]            },            {                "id": 221,                "name": "chrome test",                "parentId": 2,                "fileCount": 2            }        ]    },    {        "id": 52,        "name": "项目2",        "parentId": 1,        "fileCount": 10,        "children": [            {                "id": 54,                "name": "文件夹2-1",                "parentId": 52,                "fileCount": 10,                "children": [                    {                        "id": 55,                        "name": "文件夹2-1-1",                        "parentId": 54,                        "fileCount": 0,                        "children": [                            {                                "id": 56,                                "name": "文件夹2-1-1-1",                                "parentId": 55,                                "fileCount": 0,                                "children": [                                    {                                        "id": 57,                                        "name": "文件夹2-1-1-1-1",                                        "parentId": 56,                                        "fileCount": 0,                                        "children": [                                            {                                                "id": 58,                                                "name": "文件夹2-1-1-1-1-1",                                                "parentId": 57,                                                "fileCount": 0                                            }                                        ]                                    }                                ]                            }                        ]                    }                ]            }        ]    },    {        "id": 53,        "name": "文件夹1",        "parentId": 1,        "fileCount": 12,        "children": [            {                "id": 80,                "name": "文件夹",                "parentId": 53,                "fileCount": 11            },            {                "id": 224,                "name": "文件夹2",                "parentId": 53,                "fileCount": 0            }        ]    },    {        "id": 69,        "name": "项目3",        "parentId": 1,        "fileCount": 55,        "children": [            {                "id": 70,                "name": "文件夹1",                "parentId": 69,                "fileCount": 12,                "children": [                    {                        "id": 4,                        "name": "1",                        "parentId": 70,                        "fileCount": 3,                        "children": [                            {                                "id": 51,                                "name": "文件夹2",                                "parentId": 4,                                "fileCount": 1                            }                        ]                    }                ]            },            {                "id": 91,                "name": "文件夹",                "parentId": 69,                "fileCount": 10            },            {                "id": 102,                "name": "文件夹",                "parentId": 69,                "fileCount": 10            },            {                "id": 113,                "name": "文件夹",                "parentId": 69,                "fileCount": 10            },            {                "id": 121,                "name": "文件夹的副本",                "parentId": 69,                "fileCount": 10            },            {                "id": 136,                "name": "点点点",                "parentId": 69,                "fileCount": 0            },            {                "id": 140,                "name": "hewei",                "parentId": 69,                "fileCount": 3,                "children": [                    {                        "id": 142,                        "name": "hewei02",                        "parentId": 140,                        "fileCount": 1                    }                ]            }        ]    }]export default {    data(){        return {            treeDatas: treeDatas        }    }}
<treeTable :list="treeDatas"></treeTable>

共有1个答案

扶誉
2023-08-17

我知道了,是背景颜色的影响,把那个z-index:-1去掉,然后那个hover出现::after会覆盖文字,这里用mix-blend-mode来实现文字也可见。注意整个tree加了一个白色背景

https://codepen.io/xboxyan/pen/poqzORW

 类似资料:
  • 本文向大家介绍vue实现树形菜单效果,包括了vue实现树形菜单效果的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了vue实现树形菜单效果展示的具体代码,供大家参考,具体内容如下 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。

  • 我现在是用padding实现的,效果如 1,请问怎么实现 2的效果? 谢谢

  • 下面是我用来将mongodb版本从2.6.9升级到最新版本的命令,但它仍然显示了以前的版本。让我知道我在升级过程中做错了什么。问题是仍然显示升级后安装的旧版本。 我提到的文档--Mongodb文档 我遵循的步骤- sudo apt-key adv--keyserver hkp://keyserver.ubuntu.com:80--recv 7f0ceb10 echo“deb http://repo

  • 当我插入命令git push heroku master以便在eroku中部署时,会出现以下错误 下面是我的pom.xml 我找过类似的问题,但没有解决我的问题,我甚至在我的属性中添加了: 我正在按照本教程https://dashboard.heroku.com/apps/candidate-manager-api/deploy/heroku-git的步骤进行操作 我该怎么解决这个?

  • 本文向大家介绍js实现无限级树形导航列表效果代码,包括了js实现无限级树形导航列表效果代码的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了js实现无限级树形导航列表效果代码。分享给大家供大家参考。具体如下: 这是一款js实现无限级树形下拉导航菜单,简洁实用,用到一个已封装好的JS类,有用的大家借鉴一下。 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js

  • vue项目怎么查看node版本?