v-scroll-lock icon indicating copy to clipboard operation
v-scroll-lock copied to clipboard

Not working in vue3

Open madebyfabian opened this issue 3 years ago • 2 comments

So I installed as you install vue 3 plugins:

main.js:

import VScrollLock from 'v-scroll-lock'
app.use(VScrollLock)

and in the app

<div v-scroll-lock="true">

but nothing happens, the body is still scrollable. It fails silently, so no errors or anything.

madebyfabian avatar Oct 18 '21 20:10 madebyfabian

For anyone who want's to use this plugin for vue3, just implement your own by installing the body-scroll-lock dependency by yourself, then creating a src/plugins/BodyScrollLock.js file:

import { enableBodyScroll, disableBodyScroll, clearAllBodyScrollLocks } from 'body-scroll-lock'

export default {
  install: ( app, options ) => {
    app.directive('scroll-lock', {
      // On mount (inserted)
      mounted( el, binding ) {
        if (binding.value) {
          disableBodyScroll(el)
        }
      },

      updated( el, binding ) {
        if (binding.value) {
          disableBodyScroll(el)
        } else {
          enableBodyScroll(el)
        }
      },

      // On unmount (removed)
      unmounted( el ) {
        enableBodyScroll(el)
      }
    })
  },
}

and in src/main.js:

import BodyScrollLock from '@/plugins/BodyScrollLock'
app.use(BodyScrollLock)

madebyfabian avatar Jan 02 '22 10:01 madebyfabian

body-scroll-lock They stopped the repairs. I had to do it myself, in the same way, with a new version of typeScript. And fix these problems for everyone to use. add react hooks、vue3 example

npm i body-scroll-lock-upgrade

repair log,Refer to the releases page.

rick-liruixin avatar Dec 01 '23 14:12 rick-liruixin