若依 ruoyi 分离版 vue 简单的行内编辑实现

需要实现的效果:双击文本  -  修改文本  -  保存修改。

 

 原码:仅文本显示文字内容

<el-table-column label="商品" align="center" prop="goodsName" width="200" v-if="columns[1].visible" />

 实现双击文本、修改文本:

在上面源码基础上进行编辑,新增如下

修改后代码:

      <el-table-column label="商品" align="center" prop="goodsName" width="200" v-if="columns[1].visible">
        <template slot-scope="scope">
          <span v-if="!scope.row.isEditing" @dblclick="startEditing(scope.$index, scope.row)">{{scope.row.goodsName}}</span>
          <span v-else><el-input v-model="scope.row.goodsName" @blur="stopEditing(scope.$index, scope.row)"/></span>
        </template>
      </el-table-column>

行内文本框的双击事件、失去焦点事件:

    startEditing(index, row) {
      // 启用编辑模式:设置当前行的isEditing属性值为true,使用 this.$set 同步更新视图为文本框
      this.$set(row, 'isEditing', true);
    },
    stopEditing(index, row) {
      // 禁用编辑模式:设置当前行的isEditing属性值为false,使用 this.$set 同步更新视图为文本
      this.$set(row, 'isEditing', false);
      console.info(row);
      console.info(row.id);
      console.info(row.goodsId);
      console.info(row.goodsName);
      // 这里可以添加保存或其他逻辑
      // 调用接口,更新数据

    }

后端数据集合对象中,新增属性 isEditing

总体参考代码:

<template>  
  <el-table :data="tableData">  
    <el-table-column label="商品" align="center" width="200">  
      <template slot-scope="scope">  
        <span  
          v-if="!scope.row.isEditing"  
          @dblclick="startEditing(scope.$index, scope.row)"  
        >  
          {{ scope.row.goodsName }}  
        </span>  
        <el-input  
          v-else  
          v-model="scope.row.goodsName"  
          @blur="stopEditing(scope.$index, scope.row)"  
        />  
      </template>  
    </el-table-column>  
    <!-- 其他列... -->  
  </el-table>  
</template>  
  
<script>  
export default {  
  data() {  
    return {  
      tableData: [  
        { goodsName: '商品1', isEditing: false },  
        { goodsName: '商品2', isEditing: false },  
        // ... 其他数据  
      ],  
    };  
  },  
  methods: {  
    startEditing(index, row) {  
      this.$set(row, 'isEditing', true); // 启用编辑模式  
    },  
    stopEditing(index, row) {  
      this.$set(row, 'isEditing', false); // 禁用编辑模式  
      // 这里可以添加保存或其他逻辑  
    },  
  },  
};  
</script>

其他 

1. 想要一体版的,看这里 https://blog.csdn.net/torpidcat/article/details/101369733

2. vue-ele-editable   适用原生vue

https://github.com/dream2023/vue-ele-editable


 

相关推荐

  1. RuoYi单体Table编辑

    2024-07-10 04:30:09       29 阅读
  2. ruoyi-vue前端组件使用指南

    2024-07-10 04:30:09       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 04:30:09       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 04:30:09       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 04:30:09       58 阅读
  4. Python语言-面向对象

    2024-07-10 04:30:09       69 阅读

热门阅读

  1. MySQL快速安装(mysql8.0.30区别之前yum安装)

    2024-07-10 04:30:09       25 阅读
  2. FastGPT本地手动部署(一)mongodb和pgvector的安装

    2024-07-10 04:30:09       28 阅读
  3. 字符串

    2024-07-10 04:30:09       29 阅读
  4. 494. 目标和

    2024-07-10 04:30:09       26 阅读
  5. 微信小程序常用的事件

    2024-07-10 04:30:09       32 阅读
  6. Perl变量作用域全解析:掌握变量的可见之旅

    2024-07-10 04:30:09       29 阅读
  7. SRC漏洞挖掘技巧:修改返回包的各种姿势

    2024-07-10 04:30:09       20 阅读
  8. Linux: network: openvswitch: disk 访问速度导致不稳定

    2024-07-10 04:30:09       26 阅读
  9. 释放计算潜力:SKlearn模型并行训练指南

    2024-07-10 04:30:09       27 阅读
  10. FreeRTOS的任务间通信方式

    2024-07-10 04:30:09       34 阅读