一、问题
element中的el-switch的值默认都是true或false,但是有些时候后端接口该字段可能是0或者1,如果说再转换一次值,那就有点太费力了。如下所示:
<template><el-switchinactive-text="否"active-text="是"v-model="status"@change="changeSwitch"/>
</template>
<script>
export default {data() {return {status: false}},methods: {changeSwitch(e) {console.info(e)}}
}
</script>

二、解决
在el-switch中设置active-value和inactive-value属性,接受Boolean, String或Number类型的值
<el-switchinactive-text="否"active-text="是"active-value="1"inactive-value="0"v-model="status"
/>

三、官方文档
