配合 slot-scope 作用域插槽使用 scope.row 可以获取当前所在行的每项数据
1.监听 switch 开关的 change事件 拿到最新状态
2.发送请求 调用接口 同步数据
<el-table-column prop="mg_state" label="状态">
<!-- 作用域插槽 处理后台返回数据 true-false 0-1 -->
<template slot-scope="scope">
<!-- {
{scope.row.mg_state}} slot-scope 作用域插槽 scope.row 可以获取当前所在行的数据 -->
<!-- 开关 -->
<el-switch @change="change(scope.row)" v-model="scope.rew.mg_state"></el-switch>
</template>
</el-table-column>
// 回调函数 用户表格中的 switch 开关状态 发生改变时触发
change(usersInfo){
console.log(usersInfo);
//发送put请求修改 switch 开关 状态 请求路径:users/:uId/state/:type
this.axios.put(`users/${usersInfo.id}/state/${usersInfo.mg_state}`).then(res=>{
console