<script>
// 自定义指令 (Vue 3)
export const selectScroll = {
  beforeMount(el, binding) {
    const handleScroll = (event) => {
      binding.value(event); // 调用传进来的函数，传递事件对象
    };
    el.addEventListener('scroll', handleScroll);
    // 提供一个方法供组件清理事件监听
    el['cleanUpSelectScroll'] = () => {
      el.removeEventListener('scroll', handleScroll);
    };
  },
  unmounted(el) {
    // 组件卸载时清理事件监听
    el['cleanUpSelectScroll'] && el['cleanUpSelectScroll']();
  },
};


<template>
  <el-select v-selectScroll="handleScroll">
    <!-- options -->
  </el-select>
</template>
 
<script>
import { selectScroll } from './path/to/your/directive';
 
export default {
  directives: {
    selectScroll,
  },
  methods: {
    handleScroll(event) {
      // 处理滚动事件
      console.log('Scroll event:', event);
    },
  },
};
</script>