types(IndexBar): add scrollTo method (#7845)

This commit is contained in:
neverland 2021-01-02 16:31:24 +08:00 committed by GitHub
parent fd385bce9d
commit 3344e31a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 7 deletions

View File

@ -89,6 +89,14 @@ export default {
| ------- | ------------------------------------- |
| default | Anchor content, show index by default |
### IndexBar Methods
Use [ref](https://vuejs.org/v2/api/#ref) to get IndexBar instance and call instance methods.
| Name | Description | Attribute | Return value |
| --- | --- | --- | --- |
| scrollTo `v2.12.2` | scroll to target element | _index: number \| string_ | - |
### Less Variables
How to use: [Custom Theme](#/en-US/theme).

View File

@ -93,6 +93,14 @@ export default {
| ------- | -------------------------------- |
| default | 锚点位置显示内容,默认为索引字符 |
### IndexBar 方法
通过 ref 可以获取到 IndexBar 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。
| 方法名 | 说明 | 参数 | 返回值 |
| ------------------ | -------------- | ------------------------- | ------ |
| scrollTo `v2.12.2` | 滚动到指定锚点 | _index: number \| string_ | - |
### 样式变量
组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考[主题定制](#/zh-CN/theme)。

View File

@ -184,12 +184,7 @@ export default createComponent({
}
},
scrollToElement(element) {
const { index } = element.dataset;
if (!index) {
return;
}
scrollTo(index) {
const match = this.children.filter(
(item) => String(item.index) === index
);
@ -205,6 +200,11 @@ export default createComponent({
}
},
scrollToElement(element) {
const { index } = element.dataset;
this.scrollTo(index);
},
onTouchEnd() {
this.active = null;
},

5
types/index-bar.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import { VanComponent } from './component';
export class IndexBar extends VanComponent {
scrollTo(index: number | string): void;
}

3
types/index.d.ts vendored
View File

@ -14,6 +14,7 @@ import { DropdownItem } from './dropdown-item';
import { Field } from './field';
import { Form } from './form';
import { ImagePreview } from './image-preview';
import { IndexBar } from './index-bar';
import { Lazyload } from './lazyload';
import { List } from './list';
import { Locale } from './locale';
@ -57,7 +58,6 @@ export class GoodsActionIcon extends VanComponent {}
export class Icon extends VanComponent {}
export class Image extends VanComponent {}
export class IndexAnchor extends VanComponent {}
export class IndexBar extends VanComponent {}
export class Info extends VanComponent {}
export class Loading extends VanComponent {}
export class NavBar extends VanComponent {}
@ -108,6 +108,7 @@ export {
Form,
Field,
ImagePreview,
IndexBar,
Lazyload,
List,
Locale,