当前位置:   article > 正文

el-tooltip超出文字长度进行显示_el-tooptip设置文本最大长度超过悬浮显示

el-tooptip设置文本最大长度超过悬浮显示
  1. <template>
  2. <div class="text-tooltip">
  3. <el-tooltip
  4. class="item"
  5. :disabled="isShowTooltip"
  6. :content="content"
  7. :placement="placement"
  8. >
  9. <p class="over-flow" :class="className" @mouseover="onMouseOver(refName)">
  10. <span ref="refConName">{{ contentName }}</span>
  11. <span :ref="refName">{{ content || "--" }}</span>
  12. </p>
  13. </el-tooltip>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'textTooltip',
  19. props: {
  20. // 名称
  21. contentName: {
  22. type: String,
  23. default: ""
  24. },
  25. // 显示的文字内容
  26. content: {
  27. type: String,
  28. default: ""
  29. },
  30. // 位置
  31. placement: {
  32. type: String,
  33. default: "top"
  34. },
  35. // 外层框的样式,在传入的这个类名中设置文字显示的宽度
  36. className: {
  37. type: String,
  38. default: ""
  39. },
  40. // 为页面文字标识(如在同一页面中调用多次组件,此参数不可重复)
  41. refName: {
  42. type: String,
  43. default: ""
  44. }
  45. },
  46. data () {
  47. return {
  48. isShowTooltip: true
  49. }
  50. },
  51. methods: {
  52. onMouseOver (str) {
  53. let parentWidth = this.$refs[str].parentNode.offsetWidth;
  54. let contentWidth = this.$refs[str].offsetWidth;
  55. let contentNameWidth = this.$refs['refConName'].offsetWidth;
  56. // 若子集比中间层更宽 开启tooltip功能"
  57. if ((parentWidth - contentNameWidth) < contentWidth) {
  58. this.isShowTooltip = false;
  59. } else { // 否则 关掉tooltip功能
  60. this.isShowTooltip = true;
  61. }
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .over-flow {
  68. overflow: hidden;
  69. white-space: nowrap;
  70. text-overflow: ellipsis;
  71. }
  72. .over-flow span:first-child {
  73. color: #2c2e33;
  74. }
  75. .over-flow span:nth-child(2) {
  76. color: #797f8c;
  77. }
  78. // 传递不同的className 在此组件中写控制样式
  79. .wid190 {
  80. width: 100%;
  81. }
  82. p {
  83. margin: 0;
  84. }
  85. </style>
   <Tooltip-over  :content="formParams.cooperationModeName"  :contentName="'合作方式:'"  class="wid190" refName="cooperationModeName"></Tooltip-over> 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/91834
推荐阅读
  

闽ICP备14008679号