Install & Download:
# Yarn
$ yarn add v-scroll-lock
# NPM
$ npm install v-scroll-lock --saveDescription:
v-scroll-lock is a small yet useful Vue.js directive that prevents the body scroll when other components (e.g. modal, nav, etc) are activated.
How to use it:
1. Install & Import the v-scroll-lock module.
import VScrollLock from 'v-scroll-lock' Vue.use(VScrollLock)
2. Use the direction in your app.
<template>
<div class="modal" v-if="open">
<button @click="closeModal">X</button>
<div class="modal-content" v-scroll-lock="open">
<p>Modal Content Here</p>
</div>
</div>
</template>export default {
name: 'Modal',
data() {
return {
open: false,
}
},
methods: {
openModal() {
this.open = true
},
closeModal() {
this.open = false
},
},
}Preview:

Changelog:
09/14/2020
- v1.3.1
05/19/2020
- v1.2.0