vue滚动组件

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值