element-ui的switch的change事件

 <el-table-column
          prop="receiveStatus"
          align="center"
          label="默认收货地址"
          width="200"
        ><template slot-scope="scope">
          默认收货地址:
          <el-switch
            v-model="scope.row.receiveStatus"
            :active-value="1"
            :inactive-value="0"
            @change="switchReceiveStatus($event,scope.row)"
          />
        </template>
</el-table-column>

对应上传status方法如下:

 switchReceiveStatus(val, row) {
      var tempStatus = row.sendStatus === 0 ? 1 : 0
      var params = {}
      params[val] = row[val]
      params.id = row.id
      setReceiveOne(params).then(res => {
        if (res.success) {
          this.$message.success('修改状态成功')
          this.getAddressList()
        } else {
          // 重置switch 变回原来的状态
          row[val] = tempStatus
          this.$message.error('修改状态失败')
        }
      })
    }

你可能感兴趣的:(elementui)