仅当我的 if 语句为真时,我才尝试使用 vuejs v-for 检查单选按钮。有没有办法使用 vuejs 的 v-if/v-else 来解决这类问题?
在 php 和 html 中,我可以通过执行以下操作来实现:
<input type="radio" <? if(portal.id == currentPortalId) ? 'checked="checked"' : ''?>>
以下是我目前使用 vuejs 的结果:
<div v-for="portal in portals">
<input type="radio" id="{{portal.id}}" name="portalSelect"
v-bind:value="{id: portal.id, name: portal.name}"
v-model="newPortalSelect"
v-on:change="showSellers"
v-if="{{portal.id == currentPortalId}}"
checked="checked">
<label for="{{portal.id}}">{{portal.name}}</label>
</div>
我知道这里的 v-if 语句是为了检查是显示还是隐藏输入。
非常感谢任何帮助。
最佳答案
您可以像这样绑定(bind) checked
属性:
<div v-for="portal in portals">
<input type="radio"
id="{{portal.id}}"
name="portalSelect"
v-bind:value="{id: portal.id, name: portal.name}"
v-model="newPortalSelect"
v-on:change="showSellers"
:checked="portal.id == currentPortalId">
<label for="{{portal.id}}">{{portal.name}}</label>
</div>
关于vue.js - vuejs 设置一个单选按钮检查语句是否为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34865348/