首页 > 其他分享 >Vue3+element-plus封装文字超出一行,省略号显示,鼠标悬浮展示全部

Vue3+element-plus封装文字超出一行,省略号显示,鼠标悬浮展示全部

时间:2023-04-12 13:56:24浏览次数:41  
标签:el const String 省略号 value element iframeRefs Vue3 ref

1.组件封装

<template>
  <el-tooltip effect="dark" :disabled="isShowTooltip" :content="content" placement="top">
    <p :class="['line1', className]" @mouseover="onMouseOver(refName)">
      <span :ref="setItemRef">{{ content || '-' }}</span>
    </p>
  </el-tooltip>
</template>

<script setup lang="ts">
import { ref, defineProps } from 'vue';
const props = defineProps({
  // 显示的文字内容
  content: {
    type: String,
    default: '',
  },
  // 外层框的样式,在传入的这个类名中设置文字显示的宽度
  className: {
    type: String,
    default: 'w100',
  },
  // 为页面文字标识(如在同一页面中调用多次组件,此参数不可重复)
  refName: {
    type: String,
    default: '',
  },
});

const iframeRefs = ref({});
const setItemRef = (el, key) => {
  if (el) {
    iframeRefs.value[props.refName] = el;
  }
};
const isShowTooltip = ref(true);
const onm ouseOver = str => {
  let parentWidth = iframeRefs.value[str].parentNode.offsetWidth;
  let contentWidth = iframeRefs.value[str].offsetWidth;
  // 判断是否开启tooltip功能
  if (contentWidth > parentWidth) {
    isShowTooltip.value = false;
  } else {
    isShowTooltip.value = true;
  }
};
</script>

<style lang="scss" scoped>
.w86 {
  width: 86%;
}
.w100 {
  width: 100%;
}
</style>

2.组件引用

    <div style="width: 30px">
      <r-tooltip-over content="333我是内容内容内容内容" ref-name="ref2"></r-tooltip-over>
    </div>

3.效果

 

标签:el,const,String,省略号,value,element,iframeRefs,Vue3,ref
From: https://www.cnblogs.com/rachelch/p/17309556.html

相关文章

  • Vue3快速上手
    Vue3快速上手1.Vue3简介2020年9月18日,Vue.js发布3.0版本,代号:OnePiece(海贼王)耗时2年多、2600+次提交、30+个RFC、600+次PR、99位贡献者github上的tags地址:https://github.com/vuejs/vue-next/releases/tag/v3.0.02.Vue3带来了什么1.性能的提升打包大小减少41%初次......
  • 一个 OpenTiny,Vue2 Vue3 都支持!
    大家好,我是Kagol,OpenTiny 开源社区运营,TinyVue 跨端、跨框架组件库核心贡献者,专注于前端组件库建设和开源社区运营。今天给大家介绍如何同时在Vue2和Vue3项目中使用 TinyVue。TinyVue是一套跨端、跨框架的企业级UI组件库,支持Vue2和Vue3,支持PC端和移动端。......
  • 基于elementui的Tree虚线,实线绘制,以及懒加载,如图
     加减号用的是阿里的矢量图标库。自行去下载 路径:https://www.iconfont.cn/home/index?spm=a313x.7781069.1998910419.2 <template><divclass="content-box"><divclass="content-top-lable">系统设置</div><divstyle="padd......
  • vue3使用elmentui-plus中的图标
    按照官网这样直接引入使用,不知道为啥行不通:import{Document,MenuasIconMenu,Location,Setting,}from'@element-plus/icons-vue'使用时,需要<script>import{UserFilled}from'@element-plus/icons-vue'//使用的时候需要单独引入这个图标从......
  • vue3使用体验--用了之后再也不想用vue2
    0.个人推荐使用setup语法糖,看起来更加简洁。<scriptsetup>import{ref,reactive,onMounted}from'vue';constname=ref('李四');   //定义普通数据类型的响应式,获取/修改数据需要.value,在模板中不需要.value,可以直接使用onMounted(()=>{ //某些业务逻辑。 ......
  • Vue3 setup语法糖添加name属性
    1.安装插件vite-plugin-setup-extendnpmivite-plugin-setup-extend-D2.配置vite.config.tsimportvuefrom'@vitejs/plugin-vue'import{defineConfig}from'vite'//引入插件并使用importvueSetupExtendfrom'vite-plugin-vue-setup-extend�......
  • Element Plus错误警告 | Popper: Detected CSS transitions on at least one of the f
    这个错误的解决方案如下:1.禁用"computeStyles"修饰符的adaptive选项:这将允许平滑过渡,但可能会降低性能。禁用"computeStyles"修饰符的adaptive选项,可以在创建Popper实例时指定modifiers参数,并将computeStyles的adaptive属性设置为false。示例如下:import{c......
  • find index of elements within a range
    a=np.array([1,3,5,6,9,10,14,15,56])np.where(np.logical_and(a>=6,a<=10))-->(array([3,4,5]),)(a>=6)&(a<=10)-->array([False,False,False,True,True,True,False,False,False])a[(a>=6)&(a<=......
  • 用quasar+vue3+组合式api 实现小米商城标题栏动画
    先来看一下小米商城标题栏动画:  小米商城标题栏动画主要特点:移入时二级菜单缓慢出现;移出时二级菜单缓慢消失;在一级菜单之间移动时,二级菜单内容直接切换,没有过渡效果。实现思路一、纯css实现(❌)首先肯定是考虑:hover,但是经过试验发现,:hover可以实现鼠标移入移出时的......
  • css 实现单行、多行溢出 省略号显示
    1、单行溢出显示省略号:{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}2、多行溢出省略号:①、(缺点:此方法因为使用了webkit属性,故只能chrome等浏览器有效){-webkit-line-clamp:2;/*autoprefixer:off*/-webkit-box-orient:vertical;//防......