• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

element ui 点击单元格切换为输入框并且自动获取焦点

武飞扬头像
叮叮车576
帮助1

html

  1.  
    <el-table
  2.  
    ref="table"
  3.  
    :data="aqjyData"
  4.  
    border
  5.  
    style="width: 100%"
  6.  
    max-height="500"
  7.  
    @cell-click="rowstatus"
  8.  
    >
  9.  
    <el-table-column
  10.  
    label="序号"
  11.  
    width="150"
  12.  
    type="index"
  13.  
    />
  14.  
    <el-table-column
  15.  
    label="建议"
  16.  
    width="auto"
  17.  
    >
  18.  
    <template slot-scope="scope">
  19.  
    <span
  20.  
    v-if="!scope.row.suggestFlag "
  21.  
    >
  22.  
    {{ scope.row.suggest }}
  23.  
    </span>
  24.  
    <el-input
  25.  
    v-if="scope.row.suggestFlag "
  26.  
    ref="input"
  27.  
    v-model="scope.row.suggest"
  28.  
    placeholder="请输入内容"
  29.  
    @blur="blur(scope.row,scope.column)"
  30.  
    />
  31.  
    </template>
  32.  
    </el-table-column>
  33.  
     
  34.  
    <el-table-column
  35.  
    label="操作"
  36.  
    width="120"
  37.  
    >
  38.  
    <template slot-scope="scope">
  39.  
    <el-button
  40.  
    type="text"
  41.  
    size="small"
  42.  
    @click.native.prevent="deleteRow(scope.$index, aqjyData)"
  43.  
    >
  44.  
    移除
  45.  
    </el-button>
  46.  
    </template>
  47.  
    </el-table-column>
  48.  
    </el-table>
学新通

js

  1.  
    methods:{
  2.  
    // 点击单元格切换单元格状态为输入框
  3.  
    rowstatus(row, column, cell, event) {
  4.  
    if (column.label === '建议') {
  5.  
    row.suggestFlag = true
  6.  
    //重新获取输入框的焦点
  7.  
    this.$nextTick(() => {
  8.  
    this.$refs.input.focus()
  9.  
    })
  10.  
    }
  11.  
    },
  12.  
    // 输入框失焦事件
  13.  
    blur(row, column) {
  14.  
    // 失焦时改变输入框的状态为表格
  15.  
    if (column.label === '建议') {
  16.  
    row.suggestFlag = false
  17.  
    }
  18.  
    },
  19.  
    }
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgahccg
系列文章
更多 icon
同类精品
更多 icon
继续加载