使el-table通过操控鼠标滚轮横向滚动

1.创建directive文件夹,里面创建directive.js文件

复制代码
import Vue from 'vue';

Vue.directive('scroll-x',{
  inserted:function(el){
    let domClass = el.getAttribute('class')
    if(domClass.indexOf('el-table')<0){
      return false
    }
    const scrollDiv = el;
    if(scrollDiv==null){
      return false
    }
    scrollDiv.addEventListener('mousewheel', handler, false)
    const that = this
    function handler(event) {
      const detail = event.wheelDelta || event.detail;
      const moveForwardStep = 1;
      const moveBackStep = -1;
      let step = 0;
      if (detail < 0) {
        step = moveForwardStep * 100;
      } else {
        step = moveBackStep * 100;
      }
      let d = scrollDiv.querySelector('.el-table__body-wrapper')
      d.scrollLeft += step
    }
  }
})

2.在main.js中全局引入

import './directive/directives'
3.在vue页面中使用 v-scroll-x

<el-table

v-scroll-x

> </el-table>

相关推荐
lambo mercy9 分钟前
python入门
前端·数据库·python
GIS之路27 分钟前
GDAL 实现矢量数据读写
前端
05大叔1 小时前
MybatisPlus
java·服务器·前端
slongzhang_1 小时前
edge/Chrome浏览器闪屏/花屏
前端·chrome·edge
千里马-horse1 小时前
Rect Native bridging 源码分析--Class.h
javascript·react native·react.js·class
想要一辆洒水车1 小时前
npm包开发及私有仓库配置使用
前端
低代码布道师1 小时前
互联网医院18:前端进阶——CSS“父相子绝”打造专业级卡片交互
前端·css·低代码·小程序·云开发
luckyCover1 小时前
Vue源码分析 - 从入口到构造函数的整体流程
前端·vue.js
听风说图1 小时前
AI设计类产品分析:Lovart
前端
北辰alk1 小时前
Vue 父子组件双向绑定的终极指南:告别数据同步烦恼!
vue.js