index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <uni-shadow-root class="vant-index-anchor-index"><view class="van-index-anchor-wrapper" :style="wrapperStyle">
  3. <view :class="'van-index-anchor '+(active ? 'van-index-anchor--active van-hairline--bottom' : '')" :style="anchorStyle">
  4. <slot v-if="useSlot"></slot>
  5. <block v-else>
  6. <text>{{ index }}</text>
  7. </block>
  8. </view>
  9. </view></uni-shadow-root>
  10. </template>
  11. <script>
  12. global['__wxRoute'] = 'vant/index-anchor/index'
  13. import { VantComponent } from '../common/component';
  14. VantComponent({
  15. relation: {
  16. name: 'index-bar',
  17. type: 'ancestor',
  18. current: 'index-anchor',
  19. },
  20. props: {
  21. useSlot: Boolean,
  22. index: null,
  23. },
  24. data: {
  25. active: false,
  26. wrapperStyle: '',
  27. anchorStyle: '',
  28. },
  29. methods: {
  30. scrollIntoView(scrollTop) {
  31. this.getBoundingClientRect().then((rect) => {
  32. wx.pageScrollTo({
  33. duration: 0,
  34. scrollTop: scrollTop + rect.top - this.parent.data.stickyOffsetTop,
  35. });
  36. });
  37. },
  38. getBoundingClientRect() {
  39. return this.getRect('.van-index-anchor-wrapper');
  40. },
  41. },
  42. });
  43. export default global['__wxComponents']['vant/index-anchor/index']
  44. </script>
  45. <style platform="mp-weixin">
  46. @import '../common/index.css';.van-index-anchor{padding:0 16px;padding:var(--index-anchor-padding,0 16px);color:#323233;color:var(--index-anchor-text-color,#323233);font-weight:500;font-weight:var(--index-anchor-font-weight,500);font-size:14px;font-size:var(--index-anchor-font-size,14px);line-height:32px;line-height:var(--index-anchor-line-height,32px);background-color:initial;background-color:var(--index-anchor-background-color,transparent)}.van-index-anchor--active{right:0;left:0;color:#07c160;color:var(--index-anchor-active-text-color,#07c160);background-color:#fff;background-color:var(--index-anchor-active-background-color,#fff)}
  47. </style>