Skip to content

Commit

Permalink
feat(elevator): 暴露 ScrollTo API
Browse files Browse the repository at this point in the history
  • Loading branch information
szg2008 committed Feb 18, 2022
1 parent 5b255fa commit cfd19a1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/packages/__VUE/elevator/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,8 @@ app.use(Elevator);
| click-item | 点击内容 | key: string, item: { id: 0, name: '' } |
| click-index | 点击索引 | key: string |

### API

| 事件名 | 说明 | 参数 |
| ---------------- | ---------------------- | ------------ |
| scrollTo | 滚动到对应索引的位置 | index:number |
5 changes: 5 additions & 0 deletions src/packages/__VUE/elevator/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<script lang="ts">
import { computed, reactive, toRefs, nextTick, ref, Ref, onMounted } from 'vue';
import { createComponent } from '../../utils/create';
import { useExpose } from '../../utils/useExpose/index';
const { componentName, create } = createComponent('elevator');
import Taro, { eventCenter, getCurrentInstance } from '@tarojs/taro';
interface ElevatorData {
Expand Down Expand Up @@ -191,6 +192,10 @@ export default create({
}
});
useExpose({
scrollTo
});
return {
classes,
...toRefs(state),
Expand Down
6 changes: 5 additions & 1 deletion src/packages/__VUE/elevator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<script lang="ts">
import { computed, reactive, toRefs, nextTick, ref, Ref } from 'vue';
import { createComponent } from '../../utils/create';
import { useExpose } from '../../utils/useExpose/index';
const { componentName, create } = createComponent('elevator');
interface ElevatorData {
name: string;
Expand Down Expand Up @@ -134,7 +135,6 @@ export default create({
state.touchState.y1 = firstTouch.pageY;
state.anchorIndex = +index;
state.currentIndex = +index;
// console.log(state.currentIndex);
scrollTo(+index);
};
Expand All @@ -158,6 +158,10 @@ export default create({
context.emit('click-index', key);
};
useExpose({
scrollTo
});
return {
classes,
...toRefs(state),
Expand Down
8 changes: 0 additions & 8 deletions src/packages/__VUE/swiper/use-expose.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/packages/__VUE/swiperitem/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script lang="ts">
import { computed, reactive, inject, getCurrentInstance, watch } from 'vue';
import { createComponent } from '../../utils/create';
import { useExpose } from '../swiper/use-expose';
import { useExpose } from '../../utils/useExpose/index';
const { create, componentName } = createComponent('swiper-item');
interface IStyle {
width?: string;
Expand Down
10 changes: 3 additions & 7 deletions src/packages/__VUE/swiperitem/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script lang="ts">
import { computed, reactive, inject, getCurrentInstance, watch } from 'vue';
import { createComponent } from '../../utils/create';
import { useExpose } from '../swiper/use-expose';
import { useExpose } from '../../utils/useExpose/index';
const { create, componentName } = createComponent('swiper-item');
interface IStyle {
width?: string;
Expand All @@ -34,15 +34,11 @@ export default create({
const style: IStyle = {};
const direction = parent?.props.direction;
if (parent?.size.value) {
style[
direction === 'horizontal' ? 'width' : 'height'
] = `${parent?.size.value}px`;
style[direction === 'horizontal' ? 'width' : 'height'] = `${parent?.size.value}px`;
}
if (state.offset) {
style['transform'] = `translate${
direction === 'horizontal' ? 'X' : 'Y'
}(${state.offset}px)`;
style['transform'] = `translate${direction === 'horizontal' ? 'X' : 'Y'}(${state.offset}px)`;
}
return style;
Expand Down

0 comments on commit cfd19a1

Please sign in to comment.