【项目】UniApp实战多端企业网盘全栈开发
13 多选操作开发【二】
现在实现一下选中之后,导航栏进行对应改变的效果
index.vue
<!-- 有选中 -->
<template>
<view slot='left' class="font-md ml-3 text-primary">取消</view>
<text class="font-md font-weight-bold">已选中1个</text>
<view slot='right' class="font-md mr-3 text-primary">全选</view>
</template>
效果还行
编写选中逻辑
<nav-bar>
<!-- 未选中状态 -->
<template v-if="checkCount === 0">
<text slot='left' class="font-md ml-3">首页</text>
<template slot='right'>
<view style="width: 60rpx;height: 60rpx;"
class="flex align-center justify-center bg-light rounded-circle mr-3">
<text class="iconfont icon-zengjia"></text>
</view>
<view style="width: 60rpx;height: 60rpx;"
class="flex align-center justify-center bg-light rounded-circle mr-3">
<text class="iconfont icon-gengduo"></text>
</view>
</template>
</template>
<!-- 有选中 -->
<template v-else>
<view slot='left' class="font-md ml-3 text-primary">取消</view>
<text class="font-md font-weight-bold">已选中{{checkCount}}个</text>
<view slot='right' class="font-md mr-3 text-primary">全选</view>
</template>
</nav-bar>
计算属性
computed: {
// 选中列表
checkList() {
return this.list.filter(item => item.checked)
},
// 选中数量
checkCount() {
return this.checkList.length
}
},
效果
没毛病。