123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <template>
-
- <header>
-
- <view
- class="u-index-anchor u-border-bottom"
- :ref="`u-index-anchor-${text}`"
- :style="{
- height: $u.addUnit(height),
- backgroundColor: bgColor
- }"
- >
- <text
- class="u-index-anchor__text"
- :style="{
- fontSize: $u.addUnit(size),
- color: color
- }"
- >{{ text }}</text>
- </view>
-
- </header>
-
- </template>
- <script>
- import props from './props.js';
- import mpMixin from '../../libs/mixin/mpMixin.js';
- import mixin from '../../libs/mixin/mixin.js';
-
- const dom = uni.requireNativePlugin('dom')
-
-
- export default {
- name: 'u-index-anchor',
- mixins: [mpMixin, mixin, props],
- data() {
- return {
- }
- },
- mounted() {
- this.init()
- },
- methods: {
- init() {
-
- const indexList = uni.$u.$parent.call(this, 'u-index-list')
- if (!indexList) {
- return uni.$u.error('u-index-anchor必须要搭配u-index-list组件使用')
- }
-
- indexList.anchors.push(this)
- const indexListItem = uni.$u.$parent.call(this, 'u-index-item')
-
-
- if (!indexListItem) {
- return uni.$u.error('u-index-anchor必须要搭配u-index-item组件使用')
- }
-
- indexListItem.id = this.text.charCodeAt(0)
-
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/components.scss";
- .u-index-anchor {
- position: sticky;
- top: 0;
- @include flex;
- align-items: center;
- padding-left: 15px;
- z-index: 1;
- &__text {
- @include flex;
- align-items: center;
- }
- }
- </style>
|