Vue3当中el-tree树形控件使用

tree悬停tooltip效果

javascript 复制代码
文本过长超出展示省略号 
如果文本超出悬停显示tooltip效果 反之不显示
这里直接控制固定宽度限制 试了监听宽度没效果
javascript 复制代码
<template>
  <el-tree
    show-checkbox
    :check-strictly="true"
    :data="data"
    node-key="id"
    :props="defaultProps"
  >
    <template #default="{ node }">
      <span>
        <el-tooltip :content="node.label" :disabled="!isTextOverflow(node.label)" placement="top">
          <span class="tree-node-label">{{ node.label }}</span>
        </el-tooltip>
      </span>
    </template>
  </el-tree>
</template>

<script>
import { ref } from 'vue';

export default {
  setup() {
    const data = ref([
      { id: 1, name: 'Parent Node with very long text content that may overflow' },
      { 
        id: 2, 
        name: 'Parent',
        children: [
          { id: 21, name: 'Child Node with normal length' }
        ]
      }
    ]);

    const maxCharLength = ref(10);//定义最大字符 根据需求可调整

    const defaultProps = {
      label: 'name',
      children: 'children'
    };

    // 检测文本是否溢出
    const isTextOverflow = (label) => {
      return label.length > maxCharLength.value;
    };

    return {
      data,
      defaultProps,
      isTextOverflow
    };
  }
};
</script>

<style scoped>
.tree-node-label {
  display: inline-block;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
</style>
相关推荐
千寻技术帮13 小时前
10386_基于SpringBoot的外卖点餐管理系统
java·spring boot·vue·外卖点餐
东东5162 天前
xxx医患档案管理系统
java·spring boot·vue·毕业设计·智慧城市
码界奇点2 天前
基于Spring Boot和Vue3的无头内容管理系统设计与实现
java·spring boot·后端·vue·毕业设计·源代码管理
东东5162 天前
基于Web的智慧城市实验室系统设计与实现vue + ssm
java·前端·人工智能·后端·vue·毕业设计·智慧城市
不甘平凡的小鸟3 天前
vue3与cef3交互
前端·vue·cef3
武哥聊编程3 天前
【原创精品】基于Springboot3+Vue3的服装租赁平台
spring boot·mysql·vue·课程设计
weixin_439937763 天前
tortoiseGit 使用
java·前端·git·vue
.切切切 切萝卜3 天前
【vueconfig-proxy代理解决跨域问题】
vue·proxy模式
任小栗3 天前
uniappx实现app壳子,可直接拿来用
vue·uniapp
奔跑的web.3 天前
前端使用7种设计模式的核心原则
前端·javascript·设计模式·typescript·vue