chore(Swipe): use relation

This commit is contained in:
chenjiahan
2020-09-26 11:05:39 +08:00
parent 75a8a394ca
commit c175cdd2bb
2 changed files with 22 additions and 19 deletions
+15 -12
View File
@@ -1,7 +1,8 @@
import { computed, nextTick, onMounted, reactive } from 'vue';
import { SWIPE_KEY } from '../swipe';
import { createNamespace } from '../utils';
import { useParent } from '../composition/use-parent';
import { useExpose } from '../composition/use-expose';
import { useParent } from '../composition/use-relation';
const [createComponent, bem] = createNamespace('swipe-item');
@@ -12,17 +13,7 @@ export default createComponent({
mounted: false,
});
const setOffset = (offset) => {
state.offset = offset;
};
const { parent, index } = useParent(SWIPE_KEY, { setOffset });
onMounted(() => {
nextTick(() => {
state.mounted = true;
});
});
const { parent, index } = useParent(SWIPE_KEY);
const style = computed(() => {
const style = {};
@@ -55,6 +46,18 @@ export default createComponent({
return index.value >= prevActive || index.value <= nextActive;
});
const setOffset = (offset) => {
state.offset = offset;
};
onMounted(() => {
nextTick(() => {
state.mounted = true;
});
});
useExpose({ setOffset });
return () => (
<div class={bem()} style={style.value}>
{shouldRender.value ? slots.default?.() : null}