index-list.vue 1.4 KB
<template>
    <ul class="list-box">
        <li v-for="item in items"><a href="#{{item.index}}">{{item.name}}</a></li>
    </ul>
</template>
<style>
    .list-box {
        position: fixed;
        width: 45px;
        margin: 0;
        padding: 6px;
        right: 0;
        border-radius: 8px;
        background: #fff;
        opacity: 0.8;
        top: 0;
        overflow-y: auto;

        li {
            list-style: none;
            text-align: center;

            a {
                font-size: 26px;
            }
        }
    }

</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>