本文主要是介绍Vue学习笔记:vue-seamless-scroll滚动插件的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、安装
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.lengthhoverStop: true, // 是否开启鼠标悬停stopdirection: 0, // 0向下 1向上 2向左 3向右openWatch: true, // 开启数据实时监控刷新domsingleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3waitTime: 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>
五、效果
这篇关于Vue学习笔记:vue-seamless-scroll滚动插件的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!