el-dialog弹出框编辑

先看效果:
在这里插入图片描述官方的弹出框 官方文档el-dialog按照官方文档区写就好了,我这里就不展示“表格”和“弹出框表单”的代码了,只留下事件的代码块。
点击“编辑”时,是将行数据赋值给“编辑表单”this.editForm = Object.assign({}, row),这样就会把行数据在“编辑”中展示出来。注意:点击“编辑”事件时,加上this.dialogEditFormVisible=true,默认时,其为false,这样“弹出框”弹出时也携带着相对应的数据,修改完,点击“确认提交”就ok了。有点地方是不需要更改的,这里我加了disabled,加了它表示此处禁用(无法修改:无法修改的数据是不能变动了,比如:表里的“用户编号”、“用户账号”等是后端系统自动生成了,只可以查看,但修改可能会带来数据混乱的效果,也是保护了数据)。
对你有帮助请留下你的足迹


//触发编辑OK
        handleEdit(row){
            this.dialogEditFormVisible=true
            this.editForm = Object.assign({}, row)
            // console.log(row)
        },
        //编辑事件ok
        handleUpdate(index,row){
            
            const params = {
                name:this.editForm.label,
                usercode:this.editForm.usercode,
                username:this.editForm.username,
                phone_num:this.editForm.phone_num,
                wechat_num:this.editForm.wechat_num,
                sub_org_id:this.editForm.sub_org_id, //如何获取id??
                sub_org_name:this.editForm.sub_org_name,   //所属机构
                role_type:this.editForm.role_type,   //角色类型
                role_name:this.editForm.role_name,    //角色
                email:this.editForm.email,
                manage_org:this.editForm.manage_org,   //????????
                manage_org_name:this.editForm.manage_org_name,   //管理机构
            }
            const id = this.editForm.id
            this.$http.put('/xxx/xxxx/xxxxxx/'+ id +'/',params).then((res) => {
                if(res.status === 200){
                    this.$message.success('修改成功')
                    // this.tableDisplay()  //重新加载展示框
                    // this.reload()    //刷新当前页面
                    this.dialogEditFormVisible = false
                }else{
                    this.$message.warning('修改失败,请重新点击“编辑”')
                }
            }).catch(() => {
                this.$message.danger('请求失败')
            })
        },

这个是弹出框编辑,行内编辑会在后面写出来。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
el-table是一个基于element-ui的表格组件。编辑单元格的操作需要使用到el-table的slot和scoped-slot属性。 首先,在el-table中定义一个slot,用来渲染需要编辑的单元格。例如,可以在表格的第二列中添加一个可编辑的单元格: ```html <el-table-column label="姓名"> <template slot-scope="scope"> <span>{{ scope.row.name }}</span> </template> </el-table-column> <el-table-column label="年龄"> <template slot-scope="scope"> <span class="editable-cell">{{ scope.row.age }}</span> </template> </el-table-column> ``` 在第二列中,我们使用了一个class为editable-cell的span元素来渲染需要编辑的单元格。 接下来,我们需要定义一个scoped-slot,用来渲染编辑单元格时的框。例如,我们可以使用el-dialog组件来实现框的效果: ```html <el-table-column label="年龄"> <template slot-scope="scope"> <span class="editable-cell" @click="editCell(scope.row, 'age')">{{ scope.row.age }}</span> <el-dialog :visible.sync="dialogVisible"> <el-input v-model="editValue"></el-input> <div slot="footer"> <el-button @click="dialogVisible = false">取消</el-button> <el-button type="primary" @click="saveEdit()">保存</el-button> </div> </el-dialog> </template> </el-table-column> ``` 在这里,我们为editable-cell元素添加了一个@click事件,当单元格被点击时,会触发editCell方法。该方法会设置dialogVisible为true,显示el-dialog组件。el-dialog中包含一个el-input用来输入编辑后的值,以及一个保存和取消按钮。 在methods中定义editCell、saveEdit方法: ```js methods: { editCell(row, prop) { this.editRow = row this.editProp = prop this.editValue = row[prop] this.dialogVisible = true }, saveEdit() { this.dialogVisible = false this.editRow[this.editProp] = this.editValue } } ``` 在editCell方法中,我们记录当前需要编辑的行和属性,以及设置编辑框的值和可见性。在saveEdit方法中,我们将编辑后的值保存到数据源中,并将编辑框隐藏。 最后,为了让用户知道哪些单元格可以编辑,我们可以使用CSS样式来为编辑单元格添加一个边框或者背景色: ```css .editable-cell { cursor: pointer; border: 1px dashed #ccc; padding: 2px 6px; display: inline-block; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值