vue开关组件使用 切换时询问,确认提交,取消切换成原来状态
注意:判断里的状态类型要和页面开关设置的类型一致
<el-switch
v-model="scope.row.status"
active-color="#00A854"
active-text="开"
:active-value=0
inactive-color="#F04134"
inactive-text="关"
:inactive-value=1
@change="handleStatusChange(scope.row)"
></el-switch>
handleStatusChange(row) {
let text = row.status === 0 ? "启用" : "停用";
this.$confirm('确认要"' + text + '""' + row.name + '"角色吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return changeRoleStatus(row.id, row.status);
}).then(() => {
this.$message({message: '修改成功',type: 'success'});
}).catch(()=> {
row.status = row.status === 0 ? 1 : 0;
});
},