12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <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';
- const dom = uni.requireNativePlugin('dom')
- export default {
- name: 'u-index-anchor',
- mixins: [uni.$u.mpMixin, uni.$u.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>
|