【vue】avue-crud行编辑

一、失焦保存
1.1 双击失焦保存效果图

在这里插入图片描述

1.2 双击失焦保存示例
<template>
  <div class="app-container pull-height words">
    <avue-crud
      ref="crud"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tableOption"
      @row-update="handleUpdate"
      @row-dblclick="handleRowDBLClick">
    </avue-crud>
  </div>
</template>

<script>
import option from "./test";

export default {
  name: "menu",
  data() {
    return {
      addForm: {},
      tableLoading: false,
      tableData: [
        {
          id: 0,
          name: '张三'
        },
        {
          id: 1,
          name: '李四'
        }
      ],
      tableOption: option,
    };
  },
  created() {
  },
  mounted() {
    window.handleBlur = this.handleBlur
  },
  methods: {
    handleBlur(value){
      console.log(value)
      this.$refs.crud.rowCell(this.addForm, this.addForm.$index)
    },
    handleRowDBLClick(row, column, cell, event) {
      this.addForm = row
      console.log(row)
      this.$refs.crud.rowCell(row, row.$index)
    },
    handleUpdate(row, index, done, loading) {
      this.$message({
        showClose: true,
        message: "修改成功",
        type: "success",
      });
      done();
    }
  },
};
</script>
<style lang="scss" scoped>
</style>
export default {
  delBtn: false,
  addBtn: false,
  editBtn: false,
  addRowBtn: true,
  cellBtn: false,
  cancelBtn: false,
  menu: false,
  column: [
    {
      label: '姓名',
      prop: 'name',
      cell: true,
      rules: [
        {
          required: true,
          message: '请输入姓名',
          trigger: 'blur'
        }
      ],
      blur: (value) => window.handleBlur(value)
    }
  ]
};
二、按钮保存
2.1 按钮保存效果图

在这里插入图片描述

2.2 按钮保存示例
<template>
  <avue-crud ref="crud" :option="option" :data="data" @row-update="rowUpdate">
    <template slot-scope="{row,index}" slot="menu">
      <el-button type="primary" icon="el-icon-edit" size="small" v-if="!row.$cellEdit" @click="rowCell(row,index)" circle></el-button>
      <el-button type="success" icon="el-icon-check" size="small" v-else @click="rowCell(row,index)" circle></el-button>
      <el-button type="warning" icon="el-icon-close" size="small" v-if="row.$cellEdit" @click="rowCancel(row,index)" circle></el-button>
    </template>
  </avue-crud>
</template>

<script>

export default {
  name: 'demo.vue',
  data() {
    return {
      drawer: false,
      nodes: [],
      openId: [],
      openTitle: '',
      openData: {},
      data: [
        {
          id: 0,
          name: '张三'
        },
        {
          id: 1,
          name: '李四'
        }
      ],
      option: {
        delBtn: false,
        addBtn: false,
        editBtn: false,
        addRowBtn: true,
        cellBtn: false,
        cancelBtn: false,
        column: [
          {
            label: '姓名',
            prop: 'name',
            cell: true,
            rules: [
              {
                required: true,
                message: '请输入姓名',
                trigger: 'blur'
              }
            ]
          }
        ]
      }
    }
  },
  methods: {
    rowCell(row, index) {
      this.$refs.crud.rowCell(row, index)
    },
    rowCancel(row, index) {
      this.$refs.crud.rowCancel(row, index)
    },
    rowUpdate(form, index, done) {
      // 更新操作
      this.$message.success(
        '编辑数据' + JSON.stringify(form) + '数据序号' + index
      )
      done()
    }
  }
}
</script>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王佑辉

老板,赏点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值