|
1
|
<template>
|
vben
authored
|
2
|
<PageWrapper title="滚动组件函数示例" content="基于el-scrollbar">
|
|
3
|
<div class="my-4">
|
vben
authored
|
4
5
6
7
|
<a-button @click="scrollTo(100)" class="mr-2"> 滚动到100px位置 </a-button>
<a-button @click="scrollTo(800)" class="mr-2"> 滚动到800px位置 </a-button>
<a-button @click="scrollTo(0)" class="mr-2"> 滚动到顶部 </a-button>
<a-button @click="scrollBottom()" class="mr-2"> 滚动到底部 </a-button>
|
|
8
|
</div>
|
nebv
authored
|
9
|
<div class="scroll-wrap">
|
|
10
11
12
|
<ScrollContainer class="mt-4" ref="scrollRef">
<ul class="p-3">
<template v-for="index in 100" :key="index">
|
vben
authored
|
13
14
15
|
<li class="p-2" :style="{ border: '1px solid #eee' }">
{{ index }}
</li>
|
|
16
17
18
19
|
</template>
</ul>
</ScrollContainer>
</div>
|
vben
authored
|
20
|
</PageWrapper>
|
|
21
22
23
24
|
</template>
<script lang="ts">
import { defineComponent, ref, unref } from 'vue';
import { ScrollContainer, ScrollActionType } from '/@/components/Container/index';
|
vben
authored
|
25
26
|
import { PageWrapper } from '/@/components/Page';
|
|
27
|
export default defineComponent({
|
vben
authored
|
28
|
components: { ScrollContainer, PageWrapper },
|
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
setup() {
const scrollRef = ref<Nullable<ScrollActionType>>(null);
const getScroll = () => {
const scroll = unref(scrollRef);
if (!scroll) {
throw new Error('scroll is Null');
}
return scroll;
};
function scrollTo(top: number) {
getScroll().scrollTo(top);
}
function scrollBottom() {
getScroll().scrollBottom();
}
return {
scrollTo,
scrollRef,
scrollBottom,
};
},
});
</script>
|
nebv
authored
|
53
54
55
56
|
<style lang="less" scoped>
.scroll-wrap {
width: 50%;
height: 300px;
|
Vben
authored
|
57
|
background-color: @component-background;
|
nebv
authored
|
58
59
|
}
</style>
|