场景:开关按钮保持跟后端同步
#html
<el-table-column label="状态" align="center" prop="state" show-overflow-tooltip>
<template slot-scope="scope">
<el-switch :value="scope.row.state" @input="handleSwitch(scope.row)">
</el-switch>
</template>
</el-table-column>
#js
// 状态改变事件
async handleSwitch(row) {
let params = {
state: row.state ? '1' : '0',
teamId: row.templetId,
optType: 'del'
}
const res = await optTempletAndGradeWeight(params)
console.log('状态改变', res);
this.getList()
},
页面最好用value属性,不要用v-model,事件用@input事件,不要用@change事件,这样就可以保持同步啦