可以在 Vue3 中使用自定义指令来封装横向滚动条。首先,在 main.js 中定义指令:
Vue.directive('horizontal-scroll', {
bind(el, binding) {
el.addEventListener('wheel', e => {
if (e.deltaY) {
el.scrollLeft += e.deltaY;
}
});
}
});
可以在 Vue3 中使用自定义指令来封装横向滚动条。首先,在 main.js 中定义指令:
Vue.directive('horizontal-scroll', {
bind(el, binding) {
el.addEventListener('wheel', e => {
if (e.deltaY) {
el.scrollLeft += e.deltaY;
}
});
}
});