Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

vue v-for循环默认选中第一个

图片描述
图片描述
图片描述

为什么样式是第一个默认选中了,而里面的input radio却是最后一个
addrSelected初始值是0,
如何修改?
chooseAddr: function (index) {

    this.addrSelected = index
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<input type="radio" :checked="index==addrSelected"/>

这么写
原因你写下下面的三个,只要是存在checked属性,不论值是什么,那怕是false,也会是选中,你就把这些特殊的属性当做,存在即为真就行了。

<input type="radio" checked=""/>
<input type="radio" checked/>
<input type="radio" checked=false/>

按照你的绑定方法是,checked的值渲染为'checked'或者。正确的做法是,判断是否渲染checked这个属性


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...