1.0.1 • Published 3 years ago

@ophiuchus/index-bar v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

IndexBar 索引栏

引入

// 方式1(推荐)
import Vue from 'vue';
import IndexBar from '@ophiuchus/index-bar';

Vue.use(IndexBar);

// 方式2
import Vue from 'vue';
import { IndexBar, IndexAnchor } from '@ophiuchus/index-bar';

Vue.component(IndexBar.name, IndexBar);
Vue.component(IndexAnchor.name, IndexAnchor);

代码演示

基础用法

点击索引栏时,会自动跳转到对应的 IndexAnchor 锚点位置。

<sf-index-bar>
  <sf-index-anchor index="A" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />

  <sf-index-anchor index="B" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />

  ...
</sf-index-bar>

自定义索引列表

可以通过 index-list 属性自定义展示的索引字符列表。

<sf-index-bar :index-list="indexList">
  <sf-index-anchor index="1">标题1</sf-index-anchor>
  <sf-cell title="文本" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />

  <sf-index-anchor index="2">标题2</sf-index-anchor>
  <sf-cell title="文本" />
  <sf-cell title="文本" />
  <sf-cell title="文本" />

  ...
</sf-index-bar>
export default {
  data() {
    return {
      indexList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    };
  },
};

API

IndexBar Props

参数说明类型默认值
index-list索引字符列表string[] | number[]A-Z
z-indexz-index 层级number | string1
sticky是否开启锚点自动吸顶booleantrue
sticky-offset-top锚点自动吸顶时与顶部的距离number0
highlight-color索引字符高亮颜色string#ee0a24

IndexAnchor Props

参数说明类型默认值
index索引字符number | string-

IndexBar Events

事件名说明回调参数
select点击索引栏的字符时触发index: number | string
change当前高亮的索引字符变化时触发index: number | string

IndexAnchor Slots

名称说明
default锚点位置显示内容,默认为索引字符

IndexBar 方法

通过 ref 可以获取到 IndexBar 实例并调用实例方法,详见组件实例方法

方法名说明参数返回值
scrollTo滚动到指定锚点index: number | string-

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

名称默认值描述
@index-bar-sidebar-z-index2-
@index-bar-index-font-size@font-size-xs-
@index-bar-index-line-height@line-height-xs-
@index-bar-index-active-color@red-
@index-anchor-z-index1-
@index-anchor-padding0 @padding-md-
@index-anchor-text-color@text-color-
@index-anchor-font-weight@font-weight-bold-
@index-anchor-font-size@font-size-md-
@index-anchor-line-height32px-
@index-anchor-background-colortransparent-
@index-anchor-sticky-text-color@red-
@index-anchor-sticky-background-color@white-