第七节 卡片选中,设置默认
1.卡片选中html:<li v-for="(item,index) in filterAddress" v-bind:class="{‘check‘:index==currentIndex}" @click="currentIndex=index"> <!--循环判断currenIndex,控制当前选中卡片的样式-->js:
data:{ currentIndex:0,},2.设置默认html:
<div class="addr-opration addr-set-default" v-if="!item.isDefault"> <a href="javascript:;" class="addr-set-default-btn" @click="setDefault(item.addressId)"><i>设为默认</i></a></div><div class="addr-opration addr-default" v-if="item.isDefault">默认地址</div>js:
setDefault: function (addressId) { this.addressList.forEach(function (address,index) { if(address.addressId==addressId){ address.isDefault=true; }else{ address.isDefault=false; } })}
效果:
时间: 2024-12-26 09:43:22