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>
相关推荐
捧 花2 小时前
前端如何调用后端接口(HTML + JS & Vue )
服务器·golang·vue·api·前后端交互
扶我起来还能学_2 小时前
Vue3 proxy 数据响应式的简单实现
前端·javascript·vue
IT教程资源D6 小时前
[N_101]基于springboot,vue企业网盘系统
mysql·vue·前后端分离·springboot网盘
星光一影6 小时前
智慧停车与充电一体化管理平台:打造城市出行新生态
mysql·vue·能源·springboot·uniapp
dreams_dream7 小时前
Element UI菜单折叠后的el-menu-item属性无法修改问题解决
前端·vue
雪碧聊技术1 天前
用户登陆时,动态获取菜单图标
vue·elementplus·菜单图标icon
runepic1 天前
Vue3 + Element Plus 实现PDF附件上传下载
前端·pdf·vue
星光一影2 天前
教育培训机构消课管理系统智慧校园艺术舞蹈美术艺术培训班扣课时教务管理系统
java·spring boot·mysql·vue·mybatis·uniapp
雨季~~2 天前
前端使用ffmpeg进行视频格式转换 (WebM → MP4)
前端·typescript·ffmpeg·vue
不是,你来真的啊?2 天前
Vue3响应式原理(源码)【reactive,ref,computed】
前端·vue·源码