input框超出输入区域显示...和tooltip

   <el-tooltip placement="top" effect="dark" :content="inputValue" >
        <el-input 
           v-model="inputValue" 
           @mouseover="handleMouseover"
           @mouseout="handleMouseout" 
           @focus="focus"
           placeholder="Please input" 
        />
    </el-tooltip>
        
    handleMouseover(e) {
      if (this.isOverflow(e.target)) {
        this.toolTipVisible = true;
      }
    },
    handleMouseout() {
      this.toolTipVisible = false;
    },
    focus() {
      this.toolTipVisible = false;
    },
    isOverflow(target) {
      const inputWidth = target.offsetWidth;
      const spanEl = document.createElement("span");
      spanEl.style.visibility = "hidden";
      spanEl.style.whiteSpace = "nowrap";
      spanEl.style.position = "absolute";
      spanEl.style.left = "-9999px";
      spanEl.textContent = this.inputValue;
      document.body.appendChild(spanEl);
      const contentWidth = spanEl.offsetWidth;
      document.body.removeChild(spanEl);
      return inputWidth < contentWidth;
    },
:deep(.el-input__inner)[type="text"] {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容