1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <template>
-
- <header>
-
- <view
- class="u-index-anchor u-border-bottom"
- :ref="`u-index-anchor-${text}`"
- :style="{
- height: addUnit(height),
- backgroundColor: bgColor
- }"
- >
- <text
- class="u-index-anchor__text"
- :style="{
- fontSize: addUnit(size),
- color: color
- }"
- >{{ text }}</text>
- </view>
-
- </header>
-
- </template>
- <script>
- import { props } from './props';
- import { mpMixin } from '../../libs/mixin/mpMixin';
- import { mixin } from '../../libs/mixin/mixin';
- import { addUnit, $parent, error } from '../../libs/function/index';
-
- const dom = uni.requireNativePlugin('dom')
-
-
- export default {
- name: 'u-index-anchor',
- mixins: [mpMixin, mixin, props],
- data() {
- return {
- }
- },
- mounted() {
- this.init()
- },
- methods: {
- addUnit,
- init() {
-
- const indexList = $parent.call(this, 'u-index-list')
- if (!indexList) {
- return error('u-index-anchor必须要搭配u-index-list组件使用')
- }
-
- indexList.anchors.push(this)
- const indexListItem = $parent.call(this, 'u-index-item')
-
-
- if (!indexListItem) {
- return 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>
|