donmbelembe / vue-dragscroll

A vue directive to make a scrollable element scroll by draging to the scroll direction
https://vue-dragscroll.clebinfosys.com/
MIT License
258 stars 32 forks source link

Vue 3 support #76

Closed masterWeber closed 3 years ago

masterWeber commented 3 years ago

Does not give an error, the console is empty.

"dependencies": {
    "core-js": "^3.7.0",
    "vue": "^3.0.2",
    "vue-router": "^4.0.0-rc.2",
    "vuex": "^4.0.0-rc.1"
  },
consciousnessdev commented 3 years ago

Does not give an error, the console is empty.

"dependencies": {
    "core-js": "^3.7.0",
    "vue": "^3.0.2",
    "vue-router": "^4.0.0-rc.2",
    "vuex": "^4.0.0-rc.1"
  },

Up up still many packages not supported in Vue 3 :disappointed:

jameskirtland3 commented 3 years ago

Those who aren't interested in making their own Vue 3 dragscroll and would rather hack this one into Vue 3, here's how I adapted it to make it Vue 3 compliant:

Do not use main.js. Vue 3 changed how it registers directives, so this will not work until it is updated by the contributer/maintainer.

Vue 3 changed the directive hooks. In directive.js, change the export default to the following:

export default {
  mounted: function (el, binding, vnode) {
    init(el, binding, vnode)
  },
  updated: function (el, binding, vnode, oldVnode) {
    // update the component only if the parameters change
    if (JSON.stringify(binding.value) !== JSON.stringify(binding.oldValue)) {
      init(el, binding, vnode)
    }
  },
  unmounted: function (el, binding, vnode) {
    const target = el
    u.removeEventListeners(target, POINTER_START_EVENTS, target.md)
    u.removeEventListeners(window, POINTER_END_EVENTS, target.mu)
    u.removeEventListeners(window, POINTER_MOVE_EVENTS, target.mm)
  }
}

In utils.js, change line 28: vnode.el.dispatchEvent(event)

Then register your directive using the new convention.

import { dragscroll } from "vue-dragscroll";

const app = createApp({});

app.directive('dragscroll', dragscroll);

I'm only using dragscroll on html elements, not components, so there may be additional changes necessary to accomplish that.

donmbelembe commented 3 years ago

@jameskirtland3 please make a PR

ilearnio commented 2 years ago

@donmbelembe Why is this ticket closed? It is still an issue an nobody created a PR it seems

ilearnio commented 2 years ago

I can confirm that @jameskirtland3's solution works perfectly

donmbelembe commented 2 years ago

@ilearnio are you sure the latest version is not compatible with vue 3 ?

ilearnio commented 2 years ago

I installed the version from npm and it didn't work

donmbelembe commented 2 years ago

actually the Demo(Doc) page is using vue 3 https://github.com/donmbelembe/vue-dragscroll/blob/02699f2b1753461c25d6b82a0b983b95848f4a5a/index.html#L661

donmbelembe commented 2 years ago

@ilearnio

ilearnio commented 2 years ago

@donmbelembe The version I have installed using npm i -S vue-dragscroll is 3.0.1 and it doesn't have Vue 3 support. You can see how I forked it over here https://github.com/ilearnio/vue-dragscroll/commit/e5e1f6b08edfa68defb32132f1d2a00e1b81fa97 in order to implement @jameskirtland3's solution on top of your latest master. Without that fix it wasn't seeing the directive. I am using vue-class-components with Vue v3

donmbelembe commented 2 years ago

src/directive.js is Vue 2 src/directive-next.js is Vue 3

you can do like import { dragscrollNext } from 'vue-dragscroll';

Thank you, for reporting this, I'll make vue 3 as the default this week end

donmbelembe commented 2 years ago

@ilearnio

ilearnio commented 2 years ago

Oh, I see. Would be great, thanks!