原文地址:https://blog.csdn.net/miyachenY/article/details/114836650
<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>
对应方法如下:
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('修改状态失败')
}
})
}