Skip to content

IndexList索引列表

该组件为高性能列表组件

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

普通列表

vue

<template>

  <view class="components-index-list">

    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed>IndexList索引列表</tn-nav-bar>

    <!-- 页面内容 -->
    <view :style="{paddingTop: vuex_custom_bar_height + 'px'}">

      <tn-index-list :customBarHeight="vuex_custom_bar_height" :indexList="indexList" :scrollTop="scrollTop"
                     :stickyTop="vuex_custom_bar_height">
        <view v-for="(item, index) in list" :key="index">
          <tn-index-anchor :index="item.letter"></tn-index-anchor>
          <view v-for="(data_item,data_index) in item.data" :key="data_index"
                class="index-list-item tn-border-solid-bottom">
            {{ data_item.name }}
          </view>
        </view>
      </tn-index-list>

    </view>

  </view>

</template>

<script>
  import indexList from '../../mock/index.list.js'

  const letterArr = indexList.list.map(val => {
    return val.letter
  })
  export default {
    name: 'componentsIndexListBase',
    data() {
      return {
        // 滚动的距离
        scrollTop: 0,
        // 索引列表
        indexList: letterArr,
        list: indexList.list
      }
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop
    },
    methods: {}

  }
</script>

<style lang="scss" scoped>
  .index-list-item {
    display: flex;
    box-sizing: border-box;
    width: 100%;
    padding: 20 rpx 24 rpx;
    overflow: hidden;
    color: $tn-font-color;
    font-size: 28 rpx;
    line-height: 48 rpx;
    background-color: #FFFFFF;
  }
</style>

带头像列表

vue

<template>

  <view class="components-index-list">

    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed>IndexList索引列表</tn-nav-bar>

    <!-- 页面内容 -->
    <view :style="{paddingTop: vuex_custom_bar_height + 'px'}">

      <tn-index-list :scrollTop="scrollTop" :indexList="indexList" :customBarHeight="vuex_custom_bar_height"
                     :stickyTop="vuex_custom_bar_height">
        <view v-for="(item, index) in list" :key="index">
          <tn-index-anchor :index="item.letter"></tn-index-anchor>
          <view v-for="(data_item,data_index) in item.data" :key="data_index"
                class="index-list-item tn-border-solid-bottom">
            <image class="index-list-item__image" src="/static/favicon.ico"></image>
            <view class="index-list-item__name">{{ data_item.name }}</view>
          </view>
        </view>
      </tn-index-list>

    </view>

  </view>

</template>

<script>
  import indexList from '../../mock/index.list.js'

  const letterArr = indexList.list.map(val => {
    return val.letter
  })
  export default {
    data() {
      return {
        // 滚动的距离
        scrollTop: 0,
        // 索引列表
        indexList: letterArr,
        list: indexList.list
      }
    },
    onPageScroll(e) {
      this.scrollTop = e.scrollTop
    },
    methods: {}

  }
</script>

<style lang="scss" scoped>
  .index-list-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
    color: $tn-font-color;
    font-size: 28 rpx;

    &__image {
      width: 100 rpx;
      height: 100 rpx;
      margin: 8 rpx 8 rpx;
      margin-right: 10 rpx;
    }
  }
</style>

indexList 列表数据示例

javascript
module.exports = {
    list: [{
        "letter": "A",
        "data": [{
            "name": "阿拉斯加",
            "mobile": "13588889999",
            "keyword": "阿拉斯加ABA13588889999"
        },
            {
                "name": "阿克苏",
                "mobile": "0551-4386721",
                "keyword": "阿克苏AKESU0551-4386721"
            },
            {
                "name": "阿拉善",
                "mobile": "4008009100",
                "keyword": "阿拉善ALASHAN4008009100"
            },
            {
                "name": "阿勒泰",
                "mobile": "13588889999",
                "keyword": "阿勒泰ALETAI13588889999"
            },
            {
                "name": "阿里",
                "mobile": "13588889999",
                "keyword": "阿里ALI13588889999"
            },
            {
                "name": "安阳",
                "mobile": "13588889999",
                "keyword": "13588889999安阳ANYANG"
            }
        ]
    },
        {
            "letter": "B",
            "data": [{
                "name": "白城",
                "mobile": "该主子没有留电话~",
                "keyword": "白城BAICHENG"
            },
                {
                    "name": "白山",
                    "mobile": "13588889999",
                    "keyword": "白山BAISHAN13588889999"
                },
                {
                    "name": "白银",
                    "mobile": "13588889999",
                    "keyword": "白银BAIYIN13588889999"
                },
                {
                    "name": "保定",
                    "mobile": "13588889999",
                    "keyword": "保定BAODING13588889999"
                }
            ]
        },
        {
            "letter": "C",
            "data": [{
                "name": "沧州",
                "mobile": "13588889999",
                "keyword": "沧州CANGZHOU13588889999"
            },
                {
                    "name": "长春",
                    "mobile": "13588889999",
                    "keyword": "长春CHANGCHUN13588889999"
                }
            ]
        },
        {
            "letter": "D",
            "data": [{
                "name": "大理",
                "mobile": "13588889999",
                "keyword": "大理DALI13588889999"
            },
                {
                    "name": "大连",
                    "mobile": "13588889999",
                    "keyword": "大连DALIAN13588889999"
                }
            ]
        },
        {
            "letter": "E",
            "data": [{
                "name": "鄂尔多斯",
                "mobile": "13588889999",
                "keyword": "鄂尔多斯EERDUOSI13588889999"
            },
                {
                    "name": "恩施",
                    "mobile": "13588889999",
                    "keyword": "恩施ENSHI13588889999"
                },
                {
                    "name": "鄂州",
                    "mobile": "13588889999",
                    "keyword": "鄂州EZHOU13588889999"
                }
            ]
        },
        {
            "letter": "F",
            "data": [{
                "name": "防城港",
                "mobile": "该主子没有留电话~",
                "keyword": "防城港FANGCHENGGANG"
            },
                {
                    "name": "抚顺",
                    "mobile": "13588889999",
                    "keyword": "抚顺FUSHUN13588889999"
                },
                {
                    "name": "阜新",
                    "mobile": "13588889999",
                    "keyword": "阜新FUXIN13588889999"
                },
                {
                    "name": "阜阳",
                    "mobile": "13588889999",
                    "keyword": "阜阳FUYANG13588889999"
                },
                {
                    "name": "抚州",
                    "mobile": "13588889999",
                    "keyword": "抚州FUZHOU13588889999"
                },
                {
                    "name": "福州",
                    "mobile": "13588889999",
                    "keyword": "福州FUZHOU13588889999"
                }
            ]
        },
        {
            "letter": "G",
            "data": [{
                "name": "甘南",
                "mobile": "13588889999",
                "keyword": "甘南GANNAN13588889999"
            },
                {
                    "name": "赣州",
                    "mobile": "13588889999",
                    "keyword": "赣州GANZHOU13588889999"
                },
                {
                    "name": "甘孜",
                    "mobile": "13588889999",
                    "keyword": "甘孜GANZI13588889999"
                }
            ]
        },
        {
            "letter": "H",
            "data": [{
                "name": "哈尔滨",
                "mobile": "13588889999",
                "keyword": "哈尔滨HAERBIN13588889999"
            },
                {
                    "name": "海北",
                    "mobile": "13588889999",
                    "keyword": "海北HAIBEI13588889999"
                },
                {
                    "name": "海东",
                    "mobile": "13588889999",
                    "keyword": "海东HAIDONG13588889999"
                },
                {
                    "name": "海口",
                    "mobile": "13588889999",
                    "keyword": "海口HAIKOU13588889999"
                }
            ]
        },
        {
            "letter": "I",
            "data": [{
                "name": "ice",
                "mobile": "13588889999",
                "keyword": "佳木斯JIAMUSI13588889999"
            }]
        },
        {
            "letter": "J",
            "data": [{
                "name": "佳木斯",
                "mobile": "13588889999",
                "keyword": "佳木斯JIAMUSI13588889999"
            },
                {
                    "name": "吉安",
                    "mobile": "13588889999",
                    "keyword": "吉安JIAN13588889999"
                },
                {
                    "name": "江门",
                    "mobile": "13588889999",
                    "keyword": "江门JIANGMEN13588889999"
                }
            ]
        },
        {
            "letter": "K",
            "data": [{
                "name": "开封",
                "mobile": "13588889999",
                "keyword": "开封KAIFENG13588889999"
            },
                {
                    "name": "喀什",
                    "mobile": "13588889999",
                    "keyword": "喀什KASHI13588889999"
                },
                {
                    "name": "克拉玛依",
                    "mobile": "13588889999",
                    "keyword": "克拉玛依KELAMAYI13588889999"
                }
            ]
        },
        {
            "letter": "L",
            "data": [{
                "name": "来宾",
                "mobile": "13588889999",
                "keyword": "来宾LAIBIN13588889999"
            },
                {
                    "name": "兰州",
                    "mobile": "13588889999",
                    "keyword": "兰州LANZHOU13588889999"
                },
                {
                    "name": "拉萨",
                    "mobile": "13588889999",
                    "keyword": "拉萨LASA13588889999"
                },
                {
                    "name": "乐山",
                    "mobile": "13588889999",
                    "keyword": "乐山LESHAN13588889999"
                },
                {
                    "name": "凉山",
                    "mobile": "13588889999",
                    "keyword": "凉山LIANGSHAN13588889999"
                },
                {
                    "name": "连云港",
                    "mobile": "13588889999",
                    "keyword": "连云港LIANYUNGANG13588889999"
                },
                {
                    "name": "聊城",
                    "mobile": "18322223333",
                    "keyword": "聊城LIAOCHENG18322223333"
                },
                {
                    "name": "辽阳",
                    "mobile": "18322223333",
                    "keyword": "辽阳LIAOYANG18322223333"
                },
                {
                    "name": "辽源",
                    "mobile": "18322223333",
                    "keyword": "辽源LIAOYUAN18322223333"
                },
                {
                    "name": "丽江",
                    "mobile": "18322223333",
                    "keyword": "丽江LIJIANG18322223333"
                },
                {
                    "name": "临沧",
                    "mobile": "18322223333",
                    "keyword": "临沧LINCANG18322223333"
                },
                {
                    "name": "临汾",
                    "mobile": "18322223333",
                    "keyword": "临汾LINFEN18322223333"
                },
                {
                    "name": "临夏",
                    "mobile": "18322223333",
                    "keyword": "临夏LINXIA18322223333"
                },
                {
                    "name": "临沂",
                    "mobile": "18322223333",
                    "keyword": "临沂LINYI18322223333"
                },
                {
                    "name": "林芝",
                    "mobile": "18322223333",
                    "keyword": "林芝LINZHI18322223333"
                },
                {
                    "name": "丽水",
                    "mobile": "18322223333",
                    "keyword": "丽水LISHUI18322223333"
                }
            ]
        },
        {
            "letter": "M",
            "data": [{
                "name": "眉山",
                "mobile": "15544448888",
                "keyword": "眉山MEISHAN15544448888"
            },
                {
                    "name": "梅州",
                    "mobile": "15544448888",
                    "keyword": "梅州MEIZHOU15544448888"
                },
                {
                    "name": "绵阳",
                    "mobile": "15544448888",
                    "keyword": "绵阳MIANYANG15544448888"
                },
                {
                    "name": "牡丹江",
                    "mobile": "15544448888",
                    "keyword": "牡丹江MUDANJIANG15544448888"
                }
            ]
        },
        {
            "letter": "N",
            "data": [{
                "name": "南昌",
                "mobile": "15544448888",
                "keyword": "南昌NANCHANG15544448888"
            },
                {
                    "name": "南充",
                    "mobile": "15544448888",
                    "keyword": "南充NANCHONG15544448888"
                },
                {
                    "name": "南京",
                    "mobile": "15544448888",
                    "keyword": "南京NANJING15544448888"
                },
                {
                    "name": "南宁",
                    "mobile": "15544448888",
                    "keyword": "南宁NANNING15544448888"
                },
                {
                    "name": "南平",
                    "mobile": "15544448888",
                    "keyword": "南平NANPING15544448888"
                }
            ]
        },
        {
            "letter": "O",
            "data": [{
                "name": "欧阳",
                "mobile": "15544448888",
                "keyword": "欧阳ouyang15544448888"
            }]
        },
        {
            "letter": "P",
            "data": [{
                "name": "盘锦",
                "mobile": "15544448888",
                "keyword": "盘锦PANJIN15544448888"
            },
                {
                    "name": "攀枝花",
                    "mobile": "15544448888",
                    "keyword": "攀枝花PANZHIHUA15544448888"
                },
                {
                    "name": "平顶山",
                    "mobile": "15544448888",
                    "keyword": "平顶山PINGDINGSHAN15544448888"
                },
                {
                    "name": "平凉",
                    "mobile": "15544448888",
                    "keyword": "平凉PINGLIANG15544448888"
                },
                {
                    "name": "萍乡",
                    "mobile": "15544448888",
                    "keyword": "萍乡PINGXIANG15544448888"
                },
                {
                    "name": "普洱",
                    "mobile": "15544448888",
                    "keyword": "普洱PUER15544448888"
                },
                {
                    "name": "莆田",
                    "mobile": "15544448888",
                    "keyword": "莆田PUTIAN15544448888"
                },
                {
                    "name": "濮阳",
                    "mobile": "15544448888",
                    "keyword": "濮阳PUYANG15544448888"
                }
            ]
        },
        {
            "letter": "Q",
            "data": [{
                "name": "黔东南",
                "mobile": "15544448888",
                "keyword": "黔东南QIANDONGNAN15544448888"
            },
                {
                    "name": "黔南",
                    "mobile": "15544448888",
                    "keyword": "黔南QIANNAN15544448888"
                },
                {
                    "name": "黔西南",
                    "mobile": "15544448888",
                    "keyword": "黔西南QIANXINAN15544448888"
                }
            ]
        },
        {
            "letter": "R",
            "data": [{
                "name": "日喀则",
                "mobile": "15544448888",
                "keyword": "日喀则RIKAZE15544448888"
            },
                {
                    "name": "日照",
                    "mobile": "15544448888",
                    "keyword": "日照RIZHAO15544448888"
                }
            ]
        },
        {
            "letter": "S",
            "data": [{
                "name": "三门峡",
                "mobile": "15544448888",
                "keyword": "三门峡SANMENXIA15544448888"
            },
                {
                    "name": "三明",
                    "mobile": "15544448888",
                    "keyword": "三明SANMING15544448888"
                },
                {
                    "name": "三沙",
                    "mobile": "15544448888",
                    "keyword": "三沙SANSHA15544448888"
                }
            ]
        },
        {
            "letter": "T",
            "data": [{
                "name": "塔城",
                "mobile": "15544448888",
                "keyword": "塔城TACHENG15544448888"
            },
                {
                    "name": "漯河",
                    "mobile": "15544448888",
                    "keyword": "漯河TAHE15544448888"
                },
                {
                    "name": "泰安",
                    "mobile": "15544448888",
                    "keyword": "泰安TAIAN15544448888"
                }
            ]
        },
        {
            "letter": "W",
            "data": [{
                "name": "潍坊",
                "mobile": "15544448888",
                "keyword": "潍坊WEIFANG15544448888"
            },
                {
                    "name": "威海",
                    "mobile": "15544448888",
                    "keyword": "威海WEIHAI15544448888"
                },
                {
                    "name": "渭南",
                    "mobile": "15544448888",
                    "keyword": "渭南WEINAN15544448888"
                },
                {
                    "name": "文山",
                    "mobile": "15544448888",
                    "keyword": "文山WENSHAN15544448888"
                }
            ]
        },
        {
            "letter": "X",
            "data": [{
                "name": "厦门",
                "mobile": "15544448888",
                "keyword": "厦门XIAMEN15544448888"
            },
                {
                    "name": "西安",
                    "mobile": "15544448888",
                    "keyword": "西安XIAN15544448888"
                },
                {
                    "name": "湘潭",
                    "mobile": "15544448888",
                    "keyword": "湘潭XIANGTAN15544448888"
                }
            ]
        },
        {
            "letter": "Y",
            "data": [{
                "name": "雅安",
                "mobile": "15544448888",
                "keyword": "雅安YAAN15544448888"
            },
                {
                    "name": "延安",
                    "mobile": "15544448888",
                    "keyword": "延安YANAN15544448888"
                },
                {
                    "name": "延边",
                    "mobile": "15544448888",
                    "keyword": "延边YANBIAN15544448888"
                },
                {
                    "name": "盐城",
                    "mobile": "15544448888",
                    "keyword": "盐城YANCHENG15544448888"
                }
            ]
        },
        {
            "letter": "Z",
            "data": [{
                "name": "枣庄",
                "mobile": "15544448888",
                "keyword": "枣庄ZAOZHUANG15544448888"
            },
                {
                    "name": "张家界",
                    "mobile": "15544448888",
                    "keyword": "张家界ZHANGJIAJIE15544448888"
                },
                {
                    "name": "张家口",
                    "mobile": "15544448888",
                    "keyword": "张家口ZHANGJIAKOU15544448888"
                }
            ]
        },
        {
            "letter": "#",
            "data": [{
                "name": "其他.",
                "mobile": "16666666666",
                "keyword": "echo16666666666"
            }]
        }
    ]
}