步骤一,在所在修改按钮的外层包裹的标签中 template 内放入 slot-scope='scope'
<template slot-scope='scope'>
<el-button></el-button> //修改按钮
</template>
步骤二,所在的修改按钮中放入点击事件
代码解读:点击事件启动时候,调用 showEditDialog 方法的时候,把用户的 id 通过,scope.row.id 给传进去,
<el-button @click='showEditDialog(scope.row.id)'>
<el-button>
步骤三,methods 中通过定义 showEditDialog 方法名,进行接收 id , 调用 api 接口 ,查询用户信息, 把查询到的信息 保存到了 editForm 这个表单数据对象上
async showEditDialog(id) { // 接收id
//根据id 调用api 接口 查询用户信息
const { data: res } = await this.$http.get('users/' + id)
//如果请求的状态码非200的话,则请求失败,return 终止后续操作,并给到用户一个错误提示信息
if(res.meta.status !== 200) {
return this.$message.error('状态码不是200,请求不成功,查询用户信息失败!')
}
//否则状态码是200,请求成功,则将查询到的用户信息保存到了这个 editForm 这个表单数据对象上
this.editForm = res.data
}