关于解决switch开关属性中active-value=“1“为数值形失败的问题
问题详述
如下列代码中,我想让switch打开的值(active-value)和switch关闭的值(inactive-value)都取成数值形,但是目前是把属性设置为字符串“1”。
因为等号右边的内容是包含在引号中的,所以Vue会将其视为字符串。
<el-table-column label="状态" align="center" width="80"><template slot-scope="scope"><el-switchv-model="scope.row.onlineStatus"active-value= "1"inactive-value= "0"@change="handleStatusChange(scope.row)"v-hasPermi="['net:gw:switchStatus']"></el-switch></template></el-table-column>
解决办法
把active-value = "1"前面加上“:”号,即:active-value= "1"。
这将属性值设置为数值1,冒号表示这是一个动态绑定,Vue会将等号右边的内容作为javascript代码进行解析,所以1被视为数值。
<template slot-scope="scope"><el-switchv-model="scope.row.onlineStatus":active-value= "1":inactive-value= "0"@change="handleStatusChange(scope.row)"v-hasPermi="['net:gw:switchStatus']"></el-switch></template>