Vue.js 无效道具:道具的类型检查失败;“值”;。应为布尔值,获取值为“的字符串”;0“;
我在我的Laravel项目中使用了这个包Vue.js 无效道具:道具的类型检查失败;“值”;。应为布尔值,获取值为“的字符串”;0“;,vue.js,Vue.js,我在我的Laravel项目中使用了这个包 Vue.js toggle/switch button. 在用户组件中,我使用这个切换/切换按钮来显示用户表中的状态 <tr v-for="user in users"> <td>{{user.id}}</td> <td>{{user.name}}</td> <td><toggle-button :value="
Vue.js toggle/switch button.
在用户组件中,我使用这个切换/切换按钮来显示用户表中的状态
<tr v-for="user in users">
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td><toggle-button :value="user.status"
:labels="{checked: 'On', unchecked: 'Off'}"/>
</td>
<tr>
{{user.id}
{{user.name}
但是抛出错误预期为布尔值,得到了带值的字符串。我使用了v-model=“user.status”但不起作用。这里出了什么问题?最简单的解决方案是:
<toggle-button :value="!!parseInt(user.status)"
:labels="{checked: 'On', unchecked: 'Off'}"/>
您的
user.status
值为字符串。当值为'0'
时,它将返回false
,如果值为其他值('1',2'
)将返回true
最简单的解决方案是:
<toggle-button :value="!!parseInt(user.status)"
:labels="{checked: 'On', unchecked: 'Off'}"/>
您的
user.status
值为字符串。当值为'0'
时,它将返回false
,如果值为其他值('1','2'
),它将返回true
,用户状态的值是多少?@boussadjrahim 1或0用户状态的值是多少?
?@boussadjrahim 1或0