實現效果以下
api
結構數組
<el-table-column sortable label="操做"> <template slot-scope="scope"> <el-button type="primary" @click="getMembers(scope.row.id)">成員</el-button> <el-buttontype="primary" @click="delRole(scope.row.id, scope.$index)">刪除</el-button> </template> </el-table-column> //scope.$index 獲取當前行的index
// 打開新增成員post
openAddStaff() { this.getAllStaff(); }, // 肯定新增 addStaff() { if (!this.user) { this.$message.error("請選擇用戶!"); return; } this.$post( "/api/RoleMemberController/add", { userId: this.user.split("/")[0], roleId: this.roleId }, data => { console.log(data,111) this.$message.success("添加成功!"); this.dialogAddStaffVisible = false; let item = { id: data.rm.id, userId: data.rm.userId, userCname: this.user.split("/")[1] }; this.staffList.push(item);//從數組中添加當前行 } ); },
// 刪除員工this
delStaff(id, index) { this._confirm("肯定刪除嗎?", () => { this.$post("/api/RoleMemberController/delOne", { id: id }, data => { this.$message.success("刪除成功!"); this.staffList.splice(index, 1);//從數組中刪除當前行 }); }); },