一、vue3和vue2滚动列表页面
1.下载插件
npm install vue3-seamless-scroll --save
2.引用
import { Vue3SeamlessScroll } from ‘vue3-seamless-scroll’
3.使用
//1
<Vue3SeamlessScroll
class="scroll"
:list="list"
:step="0.5"
>
<div
v-for="(item,index) in list"
:key="index"
class="item"
>
<div
class="name"
:style="{color:item.color}"
>
{{ item.name }}
</div>
<div class="num">
{{ item.num }}
</div>
</div>
</Vue3SeamlessScroll>
//2
<script>
import { reactive, toRefs } from 'vue'
import { Vue3SeamlessScroll } from 'vue3-seamless-scroll'
export default {
components: {
Vue3SeamlessScroll
},
setup () {
const state = reactive({
list: [
{ name: '书店', num: '10', color: '#fff'},
{ name: '医院', num: '20', color: '#00' }
]
})
return {
...toRefs(state)
}
}
}
</script>
//3
.scroll{
height: 80px;
}
二、vue2滚动列表页面
1.下载插件
npm installvue-seamless-scroll --save
2.引用
import vueSeamlessScroll from “vue-seamless-scroll”;
3.使用
//1
<vueSeamlessScroll
:data="monitorStation" :class-option="option">
<div v-for="(item, index) in monitorStation" :key="index">
<div class="item item_type">{{ item.id }}</div>
<div class="item item_endTime">{{ item.time }}</div>
<div class="item item_duration">{{ item.state }}</div>
<hr />
</div>
</div>
</vueSeamlessScroll>
//2
<script>
import vueSeamlessScroll from "vue-seamless-scroll";
export default {
components: {
vueSeamlessScroll,
},
data() {
return {
monitorStation: [
{
id: 1,
time: "2022",
state: "预警",
},
{
id: 2,
time: "2021",
state: "预警1",
}
]
};
},
computed: {
option() {
return {
step: 0.3, // 数值越大速度滚动越快
limitMoveNum: this.monitorStation.length, // 开始无缝滚动的数据量
hoverStop: true, // 是否开启鼠标悬停stop
direction: 1, // 0向下 1向上 2向左 3向右
openWatch: true, // 开启数据实时监控刷新dom
singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
waitTime: 1000, // 单步运动停止的时间(默认值1000ms)
};
},
},
//控制字数
filters: {
handleText(text) {
if (text.length > 23) {
return text.slice(0, 23) + "…";
} else {
return text;
}
},
}
};
</script>