uview-ui_components_u-index-anchor_u-index-anchor.vue

<template>

    <!-- 支付宝小程序使用$u.getRect()获取组件的根元素尺寸,所以在外面套一个"壳" -->

    <view>

        <view class="u-index-anchor-wrapper" :id="$u.guid()" :style="[wrapperStyle]">

            <view class="u-index-anchor " :class="[active ? 'u-index-anchor--active' : '']" :style="[customAnchorStyle]">

                <slot v-if="useSlot" />

                <block v-else>

                    <text>{{ index }}</text>

                </block>

            </view>

        </view>

    </view>

</template>

<script>

    /**

     * indexAnchor 索引列表锚点

     * @description 通过折叠面板收纳内容区域,搭配<u-index-anchor>使用

     * @tutorial https://www.uviewui.com/components/indexList.html#indexanchor-props

     * @property {Boolean} use-slot 是否使用自定义内容的插槽(默认false)

     * @property {String Number} index 索引字符,如果定义了use-slot,此参数自动失效

     * @property {Object} custStyle 自定义样式,对象形式,如"{color: 'red'}"

     * @event {Function} default 锚点位置显示内容,默认为索引字符

     * @example <u-index-anchor :index="item" />

     */

    export default {

        name: "u-index-anchor",

        props: {

            useSlot: {

                type: Boolean,

                default: false

            },

            index: {

                type: String,

                default: ''

            },

            customStyle: {

                type: Object,

                default () {

                    return {}

                }

            }

        },

        data() {

            return {

                active: false,

                wrapperStyle: {},

                anchorStyle: {}

            }

        },

        created() {

            this.parent = false;

        },

        mounted() {

            this.parent = this.$u.$parent.call(this, 'u-index-list');

            if(this.parent) {

                this.parent.children.push(this);

                this.parent.updateData();

            }

        },

        computed: {

            customAnchorStyle() {

                return Object.assign(this.anchorStyle, this.customStyle);

            }

        }

    }

</script>

<style lang="scss" scoped>

    @import "../../libs/css/style.components.scss";

   

    .u-index-anchor {

        box-sizing: border-box;

        padding: 14rpx 24rpx;

        color: #606266;

        width: 100%;

        font-weight: 500;

        font-size: 28rpx;

        line-height: 1.2;

        background-color: rgb(245, 245, 245);

    }

    .u-index-anchor--active {

        right: 0;

        left: 0;

        color: #2979ff;

        background-color: #fff;

    }

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值