1、先下载安装
npm install vue-seamless-scroll --save
也可使用淘宝镜像下载
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install vue-seamless-scroll --save
2、在页面中简单使用
<template>
<div>
<vue-seamless-scroll :data="realtimeStore" class="seamless-warp" :class-option="defaultOption">
<el-table :data="realtimeStore" >
<template slot-scope="scope">
<a class="rank-a-1">交易计费</a>
</template>
</el-table-column>
<el-table-column
prop="_source.masterOrderInfo.itemCount"
label="件数"
:show-overflow-tooltip="true"
min-width="10%"
align="center"
>
</el-table-column>
</el-table>
</vue-seamless-scroll>
</div>
</template>
<script>
import vueSeamlessScroll from 'vue-seamless-scroll'
export default {
data(){
return {
realtimeStore:[],
}
},
components:{
realTimeStoreInfo,
vueSeamlessScroll
},
computed:{
defaultOption () {
return {
step: 0.4, // 数值越大速度滚动越快
limitMoveNum: this.realtimeStore.length, // 开始无缝滚动的数据量 this.realtimeStore.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)
}
}
}
}
</script>
3、点击事件
因为在这个滚动组件中,点击事件有时候不会触发。所以在滚动组件外面一层添加点击事件,通过事件对象获取要点击的子元素。
<template>
<div @click="dianji($event)">
<vue-seamless-scroll :data="realtimeStore" class="seamless-warp" :class-option="defaultOption">
<el-table :data="realtimeStore" >
<template slot-scope="scope">
//再点击交易计费时,触发dianji()这个函数。需要传递数据时,可使用 :data-自定义变量 = "数据"
<a class="rank-a-1" id="rank1" :data-dept="JSON.stringify(scope.row)">交易计费</a>
</template>
</el-table-column>
<el-table-column
prop="_source.masterOrderInfo.itemCount"
label="件数"
:show-overflow-tooltip="true"
min-width="10%"
align="center"
>
</el-table-column>
</el-table>
</vue-seamless-scroll>
</div>
</template>
<script>
import vueSeamlessScroll from 'vue-seamless-scroll'
export default {
data(){
return {
realtimeStore:[],
}
},
components:{
realTimeStoreInfo,
vueSeamlessScroll
},
computed:{
defaultOption () {
return {
step: 0.4, // 数值越大速度滚动越快
limitMoveNum: this.realtimeStore.length, // 开始无缝滚动的数据量 this.realtimeStore.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)
}
}
},
methods:{
//点击交易计费时,触发此函数
dianji(e){
console.log(e)
console.log(e.target)
//利用事件对象
if(e.target.id == 'rank1'){
//接受传递的是数据
console.log(e.target.dataset.dept)
}
}
}
}
</script>