使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>

相关推荐
lili-felicity几秒前
React Native for Harmony 数字验证码输入功能
javascript·react native·react.js
ℋᙚᵐⁱᒻᵉ鲸落2 分钟前
【Vue3】Element Plus 表单显示自定义校验错误
前端·javascript·vue.js
程序员小寒3 分钟前
聊一聊 CommonJS 和 ES6 Module
前端·ecmascript·es6
Java后端的Ai之路3 分钟前
【AI应用开发工程师】-Gemini写前端的一个坑
前端·人工智能·gemini·ai应用开发工程师
亿元程序员4 分钟前
最近很火的一个拼图游戏,老板让我用Cocos3.8做一个...
前端
m0_748250034 分钟前
C++ Web 编程
开发语言·前端·c++
lili-felicity5 分钟前
React Native for Harmony:消息列表页面未读标记完整实现
javascript·react native·react.js
切糕师学AI5 分钟前
Vue 中的响应式布局
前端·javascript·vue.js
行者967 分钟前
Flutter适配OpenHarmony:跨平台开发热门标签组件,从数据到交互的完整实现
前端·flutter·harmonyos·鸿蒙
晷龙烬9 分钟前
Vue组件使用三步走:创建、注册、使用(Vue2/Vue3双版本详解)
前端·javascript·vue.js