效果展示
1.在全局css上 下拉选择框-多选-内容过长-用…代替
.el-tag.el-tag--info {
background-color: #f4f4f5;
border-color: #e9e9eb;
color: #909399;
max-width: calc(100% - 50px);
}
.el-tag.el-tag--info:nth-child(1) {
width: calc(100% - 50px);
}
.el-tag.el-tag--info:nth-child(1) .el-select__tags-text {
width: calc(100% - 20px);
float: left;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
2.鼠标悬浮显示全部
此为html部分
<el-tooltip
class="item"
:disabled="isTooltipDisabled"
:content="selectTooltipArr.join(',')"
placement="top-start"
>
<el-select
value-key="id"
v-model="queryForm.productAbility"
multiple
placeholder="请选择"
>
<el-option
v-for="item in productOptions"
:key="item.id"
:label="item.name"
:value="item"
>
</el-option>
</el-select>
</el-tooltip>
此为js部分
<script>
export default {
name: 'Workbench',
data() {
return {
isTooltipDisabled: true,//判断是否展示tooltip提示
selectTooltipArr: [],//tooltip所展示数据
// select多选数据
productOptions: [
{ id: '2', name: '测试数据测试数据测试数据测试数据测试数据测试数据' },
{ id: '3', name: '测试1' },
{ id: '21', name: '测试2测试2测试2' },
{ id: '222', name: '测试3测试3测试3测试3测试3' }
],
// 绑定的数据
queryForm: {
productAbility: []
}
}
},
watch: {
'queryForm.productAbility'(newVal) {
//因为我这个地方select绑定的value为一个对象 所以要进行处理
this.selectTooltipArr = []
newVal.forEach((element) => {
this.selectTooltipArr.push(element.name)
})
// 处理完成 数据格式为['测试数据测试数据测试数据测试数据测试数据测试数据','测试1']
const that = this
this.$nextTick(function () {
if (!newVal.length) {
return (that.isTooltipDisabled = true)
}
if (newVal.length > 1) {
that.isTooltipDisabled = false
} else {
that.isTooltipDisabled = true
// 获取元素
const obj2 = document.querySelector('.el-select__tags-text')
if (typeof obj2 !== 'undefined') {
that.isTooltipDisabled = obj2.scrollWidth <= obj2.offsetWidth
} else {
that.isTooltipDisabled = true
}
}
})
}
}
}
</script>