vue vant 通讯录组件

1.处理数据

引入第三方库将汉字转换成拼音,再提取首字母去完成匹配

import pinyin from "wl-pinyin"

定义一个字母表数组

index:["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

格式化数据

this.index.forEach((item) => {
                    this.allResidentList[item] = [];//this.allResidentList后台传的数据
                    details.data.forEach((el) => {
                        let first = pinyin.getFirstLetter(el.fullName).substring(0, 1);
                        if (first == item) {
                            this.allResidentList[item].push(el)
                        }
                    })
                })

格式化之后的数据

 2.组件引入

<van-index-bar :class="{ hideSidebar: hideSidebar }" :sticky="false">
        <van-index-anchor :index="index" v-for="(item,index) in resident" :key="index">
            <span class="indexWord">{{index}}</span>
            <div class="item" @click="goMsgReply" v-for="citem of item" :key="citem.id">
                <van-row class="patient bor">
                    <van-col span="12">
                        <div class="patient-left">
                            <img v-if="citem.imgUrl" :src="citem.imgUrl" alt="" />
                            <img v-else src="../../../assets/defaultHeadImg.png" alt="" />
                            <div class="patient-msg">
                                <div class="patient-txt">
                                    <div class="name">{{ citem.fullName }}</div>
                                    <span>{{ citem.sex==0?'女':'男' }}</span>
                                    <span>{{ citem.age }}岁</span>
                                </div>
                                <div class="flex">
                                    <span class="tag" v-for="tag of citem.diseaseTags" :key="tag">{{ tag }}</span>
                                </div>
                            </div>
                        </div>
                    </van-col>
                    <van-col span="12">
                        <div class="patient-right">
                            <div class="txt">{{ citem.dossierFlag }} {{ citem.signFlag }}</div>
                        </div>
                    </van-col>
                </van-row>
            </div>

        </van-index-anchor>
    </van-index-bar>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值