zoukankan      html  css  js  c++  java
  • vue+Element 表格编辑

    先上效果

     

    <template>
      <div>
        <el-table  :data="tableData" style=" 100%">
          <div v-for="(item,index) in tableTitle" :key="index" >
            <el-table-column :prop="item.prop" :label="item.title" :width="item.width" align='center'>
              <template slot-scope="{row,$index}">
                <el-input v-model="row[item.prop]" v-if="currentEdit === $index" @keyup.enter.native="finishEditClick()"></el-input>
                <span v-else>{{row[item.prop]}}</span>
              </template>
            </el-table-column>
          </div>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
              <el-button type="text" size="small" @click="finishEditClick(scope)"  v-if="currentEdit === scope.$index">完成</el-button>
              <el-button type="text" size="small" @click="EditClick(scope)" v-else>编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </template>
    export default {
      data() {
        return {
          currentEdit:-1,
          tableTitle: [
            {
              title: "日期",
              prop: "date"
            },
            {
              title: "姓名",
              prop: "name"
            },
            {
              title: "地址",
              prop: "address"
            }
          ],
          tableData: [
            {
              date: "2016-05-02",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1518 弄"
            },
            {
              date: "2016-05-04",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1517 弄"
            },
            {
              date: "2016-05-01",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1519 弄"
            },
            {
              date: "2016-05-03",
              name: "王小虎",
              address: "上海市普陀区金沙江路 1516 弄"
            },
            {
              date: "2019-10-24",
              name: "嘻嘻",
              address: "上海市普陀区金沙江路 1520 弄"
            }
          ]
        };
      },
      methods: {
        //   查看
        handleClick(row) {
          console.log(row);
        },
        //编辑
        EditClick(scope) {
          console.log(scope);
          this.currentEdit = scope.$index;
        },
        // 完成
        finishEditClick() {
          this.currentEdit = -1
        }
      }
    };

    先贴出代码 直接复制可以有一个小Demo

  • 相关阅读:
    L1-018 大笨钟 (10分)
    L1-017 到底有多二 (15分)
    L1-016 查验身份证 (15分)
    L1-015 跟奥巴马一起画方块 (15分)
    L1-014 简单题 (5分)
    L1-013 计算阶乘和 (10分)
    L1-012 计算指数 (5分)
    L1-011 A-B (20分)
    L1-010 比较大小 (10分)
    L1-009 N个数求和 (20分)
  • 原文地址:https://www.cnblogs.com/TreeCTJ/p/11733194.html
Copyright © 2011-2022 走看看