Vue realizes the installation and use of vue-seamless-scroll plugin

Vue realizes the installation and use of vue-seamless-scroll plugin

1. Installation

npm install vue-seamless-scroll --save

2. Introduction

Introduce and use vue-seamless-scroll in main.js

import scroll from 'vue-seamless-scroll'
Vue.use(scroll)

Plug-in online presentation document

3. Directly upload the code

<template>
  <div class="" style="width: 500px;height: 500px">
    <!-- 表头 -->
    <div class="warp-title" style="height: 25px;background-color: #f5f7fa;">
      <ul class="item">
        <li>
          <span class="title" style="width: 150px">标题</span>
          <span class="date" style="width: 150px">时间</span>
        </li>
      </ul>
    </div>
    <!-- 表格滚动区 -->
    <div>
      <vue-seamless-scroll :style="{height: this.scrollHeight + 'px' }" :data="listData"
                           :class-option="defaultOption" class="warp-content">
        <ul class="item">
          <li v-for="(item, index) in listData"
              :style="{backgroundColor:((index+1)%2 == 0) ? '#f0f9eb' : '#ffffff'}">
            <span class="title" style="width: 150px" v-text="item.title"></span>
            <span class="date" style="width: 150px" v-text="item.date"></span>
          </li>
        </ul>
      </vue-seamless-scroll>
    </div>
  </div>
</template>

<script>
  export default {
    
    
    data() {
    
    
      // 这里存放数据
      return {
    
    
        scrollHeight:250,
        listData: [{
    
    
          'title': '第一行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第二行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第三行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第四行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第五行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第六行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第七行',
          'date': '2017-12-16'
        }, {
    
    
          'title': '第八行',
          'date': '2017-12-16'
        }]
      }
    },
    // 监听属性 类似于data概念
    computed: {
    
    
      defaultOption () {
    
    
        return {
    
    
          step: 0.2, // 数值越大速度滚动越快
          limitMoveNum: 2, // 开始无缝滚动的数据量 this.dataList.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: {
    
    },
    // 监控data中的数据变化
    watch: {
    
    },
    // 生命周期 - 创建完成(可以访问当前this实例)
    created() {
    
    },
    // 生命周期 - 挂载完成(可以访问DOM元素)
    mounted() {
    
    }
  }
</script>

<style lang="less" scoped>

  .warp-title {
    
    
    overflow: hidden;
    ul {
    
    
      list-style: none;
      padding: 0;
      margin: 0 auto;
    }
    li {
    
    
      height: 20px;
      line-height: 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 15px;
    }
  }

  .warp-content {
    
    
    overflow: hidden;
    ul {
    
    
      list-style: none;
      padding: 0;
      margin: 0 auto;
    }
    li {
    
    
      height: 30px;
      line-height: 30px;
      display: flex;
      justify-content: space-between;
      font-size: 15px;
    }
  }
</style> 

4. Results

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42201180/article/details/107557277