【发布时间】:2018-10-23 07:08:20
【问题描述】:
我正在尝试使用单选按钮,以便用户可以选择其中一张照片作为他们的个人资料照片:
<ul v-for="p in myPhotos">
<li>
<div>
<div>
<div>
photo id: {{p.imgId}}
</div>
<input type="radio" v-model="profileImg" value="p.imgId"> Choose as profile image
</div>
<div><img v-bind:src="BASE_URL +'/uploads/' + userId + '/'+ p.imgId" /> </div>
</div>
</li>
</ul>
这些值是这样获取的:
created () {
axios.get(this.BASE_URL + '/profile/g/myphotos/', this.jwt)
.then( res => {
this.myPhotos = res.data.photos;
this.showUploadedPhoto = true;
this.profileImg = res.data.profileImg
})
.catch( error => {
console.log(error);
})
},
选择照片后,profileImg 变量应设置为该照片的 imgId。
问题是如何让用户在这个 v-for 循环中只选择一张照片作为头像?
更新:我正在迭代的 myPhotos 对象的照片:
【问题讨论】:
标签: vue.js