Vue表格中鼠标移入移出input显示隐藏 ,有输入值不再隐藏

Vue表格中鼠标移入移出input显示隐藏 , 不再隐藏的效果

	<el-table
          ref="table"
          :data="tableDatas"
          border
          style="width: 100%"
          :span-method="arraySpanMethod"
          id="table"
          row-key="id"
          @cell-mouse-enter="editCell"
        >
		<el-table-column
            prop="name"
            label="排序"
            min-width="80"
            header-align="center"
            align="center"
            type="name"
          >
            <template slot-scope="scope">
              <el-input
                :ref="`name-${scope.row.id}`"
                v-model="scope.row.name"
                v-show="scope.row.id === tabClickId && tabClickLabel === '排序'"
                placeholder="排序"
                @blur="inputBlur(scope.row)"
              >
              </el-input>
              <div
                class="cell-text"
                v-show="scope.row.id !== tabClickId || tabClickLabel !== '排序'"
              >
                {{ scope.row.name }}
              </div>
            </template>
         </el-table-column>
         <el-table-column
            prop="title"
            label="任务标题"
            min-width="80"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <el-input
                :ref="`title-${scope.row.id}`"
                v-model="scope.row.title"
                v-show="
                  scope.row.id === tabClickId && tabClickLabel === '任务标题'
                "
                placeholder="任务标题"
                @blur="inputBlur(scope.row)"
              >
              </el-input>
              <div
                class="cell-text"
                v-show="
                  scope.row.id !== tabClickId || tabClickLabel !== '任务标题'
                "
              >
                {{ scope.row.title }}
              </div>
            </template>
          </el-table-column>
	</el-table>

<script>
export default {
  data() {
    return {
      tabClickId: "",
      tabClickLabel: "",
      tableDatas: [
        {
          id: 1,
          name: "",
          title: "",
        },
     }
   },
   methods: {
    editCell(item, column, cell, event) {
      //根据点击的单元格判断是否可变成输入框
      switch (column.label) {
      //case内写你的不用鼠标移入显示的名称
        case "":
          return;
        default:
          this.tabClickId = item.id;
          this.tabClickLabel = column.label;
          break;
      }
    },
    // 失去焦点初始化
    inputBlur(item) {
      this.tabClickId = "";
      this.tabClickLabel = "";
      //这里还可以进行其他数据提交等操作
    },
  }

效果如下

默认

在这里插入图片描述

鼠标移入

在这里插入图片描述

鼠标移出有输入值

在这里插入图片描述

  • 27
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值