index-list.vue 1.51 KB
<template>
    <ul class="list-box">
        <li v-for="(item, index) in items" :key="index"><a class="no-intercept" :href="`#${item.index}`">{{item.name}}</a></li>
    </ul>
</template>
<style>
    .list-box {
        position: fixed;
        width: 30px;
        margin: 0;
        padding: 6px 0;
        right: 0;
        background: #fff;
        opacity: 0.8;
        top: 0;
        overflow-y: auto;

        li {
            list-style: none;
            text-align: center;
            width: 100%;

            a {
                font-size: 26px;
                display: inline-block;
                width: 100%;
            }
        }
    }

</style>
<script>
    module.exports = {
        props: {
            indexList: Array
        },
        data() {
            return {
                items: []
            };
        },
        watch: {
            indexList() {
                if (this.indexList) {
                    this.items = this.indexList;
                }
            }
        },
        created() {
            if (!this.indexList) {

                // 默认字母表索引数据
                for (let i = 65; i < 91; i++) {
                    let itemTemp = String.fromCharCode(i);

                    this.items.push({
                        index: itemTemp,
                        name: itemTemp
                    });
                }
                this.items.push({
                    index: '0~9',
                    name: '#'
                });
            }
        }
    };

</script>