默认使用方法
<el-switch
v-model="value"
active-color="#13ce66"
inactive-color="#ff4949">
</el-switch>
-----------------------------------------------------
export default {
data() {
return {
value: true
}
}
};
更改完
<el-switch
:value="value" //注意: v-model换成value!!!!
active-color="#13ce66"
inactive-color="#ff4949"
@input="changeFn(value)">
</el-switch>
-----------------------------------------------------
changeFn(value) {
let hintMes
if (value) {
hintMes = '确认关闭?';
} else {
hintMes = '确认开启?';
}
this.$confirm(hintMes , {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
value= !value
this.$message({ type: 'success', message: '更改成功!' })
}).catch(() => {
this.$message({ type: 'info', message: '取消更改!' })
})
}