el-table双击自动获取el-select下拉框焦点、自动获取el-input焦点、超出一行省略号...展示,移入上去提示框展示全部,不超出移入不展示提示框

<template>
  <div>
    <el-table :data="tableData" border>
      <el-table-column width="150" prop="name" label="姓名">
        <template slot-scope="scope">
          <div v-if="scope.row.isName">
            <el-input
              ref="customerInput"
              v-model="scope.row.name"
              @keyup.enter.native="onEditValue(scope.row)"
              @blur="onEditValue(scope.row)"></el-input>
          </div>
          <div @dblclick="onNamedbClick(scope.row)" v-else>
            <el-tooltip
              v-if="!showTitle"
              class="item"
              effect="dark"
              :content="scope.row.name"
              placement="top">
              <div class="toEllipsis" @mouseover="onShowTipsMouseenter">
                {{ scope.row.name }}
              </div>
            </el-tooltip>
            <div
              class="toEllipsis"
              @mouseover="onShowTipsMouseenter"
              v-if="showTitle">
              {{ scope.row.name }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="地址">
        <template slot-scope="scope">
          <div v-if="scope.row.isAddress">
            <el-select
              v-model="scope.row.address"
              placeholder="请选择"
              ref="address"
              @blur="onEditValue(scope.row)"
              @change="onEditValue(scope.row)">
              <el-option
                v-for="item in addressList"
                :key="item.value"
                :label="item.label"
                :value="item.value"></el-option>
            </el-select>
          </div>
          <div @dblclick="onAddressdbClick(scope.row)" v-else>
            <div>{{ scope.row.address }}</div>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showTitle: false,
      tableData: [
        {
          name: '王小虎王小虎王小虎王小虎',
          address: '测试',
          isName: false,
          isAddress: false
        },
        {
          name: '王小虎王小虎王小虎王小虎',
          address: '测试',
          isName: false,
          isAddress: false
        },
        {
          name: '王小虎王小虎王小',
          address: '测试',
          isName: false,
          isAddress: false
        }
      ],
      addressList: [
        {value: 1, label: '测试'},
        {value: 2, label: '测试2'}
      ]
    }
  },

  methods: {
    // 溢出隐藏
    onShowTipsMouseenter(e) {
      console.log(e, 'eeeeee溢出隐藏')
      var target = e.target
      let textLength = target.clientWidth
      let containerLength = target.scrollWidth
      textLength < containerLength
        ? (this.showTitle = false)
        : (this.showTitle = true)
    },

    onNamedbClick(row) {
      row.isName = true
      this.$nextTick(() => {
        this.$refs.customerInput.$el.querySelector('input').focus()
      })
    },

    onAddressdbClick(row) {
      row.isAddress = true
      this.$nextTick(() => {
        this.$refs.address && this.$refs.address.focus()
      })
    },

    onEditValue(row) {
      row.isName = false
      row.isAddress = false
    }
  }
}
</script>

<style lang="scss" scoped>
.toEllipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值