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


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

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

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

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

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

    修改后代码:

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

    ​​​​​​​

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

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

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

    总体参考代码:

    1. <template>
    2. <el-table :data="tableData">
    3. <el-table-column label="商品" align="center" width="200">
    4. <template slot-scope="scope">
    5. <span
    6. v-if="!scope.row.isEditing"
    7. @dblclick="startEditing(scope.$index, scope.row)"
    8. >
    9. {{ scope.row.goodsName }}
    10. span>
    11. <el-input
    12. v-else
    13. v-model="scope.row.goodsName"
    14. @keyup.enter.native="stopEditing(scope.$index, scope.row)"
    15. @blur="stopEditing(scope.$index, scope.row)"
    16. />
    17. template>
    18. el-table-column>
    19. el-table>
    20. template>
    21. <script>
    22. export default {
    23. data() {
    24. return {
    25. tableData: [
    26. { goodsName: '商品1', isEditing: false },
    27. { goodsName: '商品2', isEditing: false },
    28. // ... 其他数据
    29. ],
    30. };
    31. },
    32. methods: {
    33. startEditing(index, row) {
    34. this.$set(row, 'isEditing', true); // 启用编辑模式
    35. },
    36. stopEditing(index, row) {
    37. this.$set(row, 'isEditing', false); // 禁用编辑模式
    38. // 这里可以添加保存或其他逻辑
    39. },
    40. },
    41. };
    42. script>

    其他 

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

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

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


     

  • 相关阅读:
    SQL注入的注入点找法
    5G 技术、云原生开发和机器学习是推动物联网解决方案的重要助力
    【vue3+ts】项目初始化
    云原生之深入解析Jenkins多分支管道
    第五十五周总结——十一月月底总结
    Nacos集群的搭建过程详解
    Lua03——开发环境搭建
    Camtasia2023屏幕录制和视频剪辑标杆软件,制作微课/游戏视频必备工具
    java发送邮件完成密码找回功能
    数据丢失防护工具
  • 原文地址:https://blog.csdn.net/torpidcat/article/details/140038541