一、安装
npm install vue-seamless-scroll –save
二、在main.ts中全局挂载
import vueSeamlessScroll from 'vue-seamless-scroll'
Vue.use(vueSeamlessScroll)
三、在要使用该插件的子组件中引入
import vueSeamlessScroll from "vue-seamless-scroll";
@Component({
components: {
vueSeamlessScroll,
},
})
先执行
npm install @types/vue-seamless-scroll
若npm报错,执行失败,则在src文件中找到type.d.ts文件,进行声明
declare module 'vue-seamless-scroll';
之后就不会再有爆红的情况了
四、使用vue-seamless-scroll
<template>
<div class="box">
<vue-seamless-scroll :data="CardPartsStatisticsList" class="seamless-warp" :class-option="classOption">
<div class="box">
<ul class="col-list-box" ref="listScroll" >
<li v-for="(item,index) in CardPartsStatisticsList" :key="index"><span>{{item.text}}</span></li>
</ul>
</div>
</vue-seamless-scroll>
</div>
</template>
<script>
import vueSeamlessScroll from 'vue-seamless-scroll'
export default {
data() {
return {
CardPartsStatisticsList:[
{text:'1案件编号:J3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'2案件编号:Z3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'3案件编号:B3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'4案件编号:W3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'5案件编号:A3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'6案件编号:S3201445455455444 XX涉案物品24小时未入库,请及时入库'},
{text:'7案件编号:V3201445455455444 XX涉案物品24小时未入库,请及时入库'},
]
}
},
components: { //组件
vueSeamlessScroll
},
computed: {
classOption () {
return {
step: 0.2, // 数值越大速度滚动越快
limitMoveNum: 5, // 开始无缝滚动的数据量 this.dataList.length
hoverStop: true, // 是否开启鼠标悬停stop
direction: 0, // 0向下 1向上 2向左 3向右
openWatch: true, // 开启数据实时监控刷新dom
singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
}
}
},
}
</script>
<style>
.box{
width: 100%;
height: 400px;
overflow: hidden;
}
.seamless-warp{
width: 100%;
height: calc(100% - 16px);
overflow: hidden;
}
.box{
width: 100%;
height:400px;
overflow: hidden;
}
.col-list-box{
width: 100%;
}
.col-list-box li{
width: 588px;
height: 74px;
color: #ffffff;
font-size: 15px;
margin-top: 20px;
}
.col-list-box li:nth-of-type(5n+1){
background: url("~@/assets/img/col-list1.png") no-repeat;
}
.col-list-box li:nth-of-type(5n+2){
background: url("~@/assets/img/col-list2.png") no-repeat;
}
.col-list-box li:nth-of-type(5n+3){
background: url("~@/assets/img/col-list3.png") no-repeat;
}
.col-list-box li:nth-of-type(5n+4){
background: url("~@/assets/img/col-list4.png") no-repeat;
}
.col-list-box li:nth-of-type(5n+5){
background: url("~@/assets/img/col-list5.png") no-repeat;
}
.col-list-box li span{
float: left;
width: calc(100% - 87px);
height: 40px;
margin: 18px 20px;
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
</style>