欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > Vue3中使用el-table遇到的问题

Vue3中使用el-table遇到的问题

2024/10/25 17:21:15 来源:https://blog.csdn.net/XZZXBC/article/details/139883088  浏览:    关键词:Vue3中使用el-table遇到的问题

我在使用element-plus中el-table组件的时候,对于某一<el-table-column>标签内的内容设置show-overflow-tooltip属性,但这里溢出展示的tooltip的默认样式是无法像el-tooltip标签那样,直接可以修改的。默认的样式是这样:

因此,我尝试这样:

<el-table-column property="name" :label="$t('Name')" 
min-width='40%' show-overflow-tooltip><template #default="scope"><el-tooltip :content="scope.row.file_name" placement="bottom" offset="5" effect="light" :disabled="isShowFileName"><span class="name-line">{{ scope.row.file_name }}</span></el-tooltip></template>
</el-table-column>

但这样会导致同时展示两个tooltip,并且下面包裹在span标签外层的el-tooltip是会一直显示的,这里还需要写一个方法来判断当前是否溢出,这样逻辑就复杂了很多,至于如何判断,下面我会贴代码。这里我讲一下我对show-overflow-tooltip属性设置后样式的处理方法,使用官方文档中的:

注意这里这个属性是el-table的,不要写在<el-table-column>标签上,代码如下:

<el-table-column property="name" :label="$t('Name')" 
min-width='40%' show-overflow-tooltip
:tooltip-options="{placement: 'bottom', effect: 'light', offset: -10}"><template #default="scope"><el-tooltip :content="scope.row.file_name" placement="bottom" offset="5" effect="light" :disabled="isShowFileName"><span class="name-line">{{ scope.row.file_name }}</span></el-tooltip></template>
</el-table-column>

实现效果如下:

上面提到如何判断当前文本是否溢出呢,我在需要判断的元素身上绑定了@mouseenter方法,然后编写代码如下(TS代码):

<el-tooltip :content="file_name" placement="bottom" offset="10" effect="light" :disabled="isShowName"><span class="pre-info-title" @mouseenter="visibilityNameChange($event)">{{ file_name }}</span>
</el-tooltip>function visibilityNameChange(event: any) {const ev = event.targetconst evWeight = ev.scrollWidthconst contentWeight = ev.clientWidthif (evWeight > contentWeight) {// 实际宽度 > 可视宽度  文字溢出isShowName.value = false} else {// 否则为不溢出isShowName.value = true}
}

 即可判断是否溢出~

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com