控制 el-tooltip 组件是否显示:有省略号显示,没有省略号不显示

控制 el-tooltip 组件是否显示:有省略号显示,没有省略号不显示_第1张图片

<el-row v-loading="loading" :gutter="30" class="warning-wrapper">
<el-col
  v-for="(risk, index) in tableData"
  :key="index + '' + risk.zrr"
  :lg="8"
  :md="8"
  :sm="12"
  :xl="8"
  :xs="12"
  class="warning-item"
>
  <el-card class="warning-card">
    <div>
      <el-popover :offset="-100" placement="bottom-start" trigger="click" width="380">
        
        <div slot="reference" class="header-text">
          <el-tooltip
            effect="dark"
            :content="risk.zrrView"
            placement="top-start"
            :disabled="tooltipIsShow"
          >
            <span
              :class="['name', `zrrView${index}`]"
              @mouseenter="tooltipIsDisHandler(`.zrrView${index}`)"
            >
              {{ risk.zrrView }}
            span>
          el-tooltip>
          <el-tooltip
            effect="dark"
            :content="risk.zrrView !== risk.ssbmView ? risk.ssbmView : ''"
            placement="top-start"
            :disabled="tooltipIsShow"
          >
            <span
              v-if="risk.zrrView !== risk.ssbmView"
              :class="['site', `ssbmView${index}`]"
              @mouseenter="tooltipIsDisHandler(`.ssbmView${index}`)"
            >
              {{ risk.ssbmView }}
            span>
          el-tooltip>
          
        div>
      el-popover>
      <div class="warning-people" @click="openDetail(risk)">
        <div class="article-points">
          <el-tooltip
            class="item"
            effect="dark"
            :content="risk.mxmc"
            placement="top-start"
            :disabled="tooltipIsShow"
          >
            <div
              :class="[`mxmc${index}`]"
              @mouseenter="tooltipIsDisHandler(`.mxmc${index}`)"
            >
              XXXX: {{ risk.mxmc }}
            div>
          el-tooltip>
          <div>XXXX: {{ risk.cjsj }}div>
        div>
      div>
    div>
  el-card>
el-col>
el-row>
data() {
  return {
    // ...
    tooltipIsShow: false // 是否展示tooltip
  }
},
tooltipIsDisHandler(className) {
 this.$nextTick(() => {
    const dom = document.querySelector(className)
    const domScrollWidth = dom && dom.scrollWidth
    const domClientWidth = dom && dom.clientWidth
    this.tooltipIsShow = domClientWidth >= domScrollWidth
  })
}

最开始想的解决办法 (实现不了,因为在 this.$nextTick() 中计算的结果在 tooltipIsDisHandler 中无法直接 return
控制 el-tooltip 组件是否显示:有省略号显示,没有省略号不显示_第2张图片
控制 el-tooltip 组件是否显示:有省略号显示,没有省略号不显示_第3张图片

你可能感兴趣的:(elementUI,JavaScript,项目问题,javascript,前端,开发语言)