el-switch通过发送请求结果修改状态

通过v-model判断是否为true,不通过active-value和inactive-value判断。比较简单,所以直接上代码

<el-table-column label="服务状态">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.serviceStatus===1" :disabled="scope.row.status===0"  @change="switchChange(scope.row)">
          </el-switch>
        </template>
</el-table-column>
switchChange(item){
      let statusIdList = item.vos.map(m=>m.id)
      if(item){
        this.$modal.confirm(`确定要${item.serviceStatus===1?'暂停':'启用'}${item.schoolName}的服务吗`).then(()=>{
           //通过发送请求修改状态
         testService(statusIdList).then(res=>{

            })
        })
      }
    },    

 ElementPlus可以使用model-value

<el-table-column label="服务状态">
        <template slot-scope="scope">
          <el-switch :model-value="scope.row.serviceStatus===1" :disabled="scope.row.status===0"  @change="switchChange(scope.row)">
          </el-switch>
        </template>
</el-table-column>

  

posted @ 2023-01-04 14:57  初生土豆  阅读(1018)  评论(0编辑  收藏  举报