Prevent Body Scroll In Vue.js – v-scroll-lock


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'


2. Use the direction in your app.

  <div class="modal" v-if="open">
    <button @click="closeModal">X</button>
    <div class="modal-content" v-scroll-lock="open">
      <p>Modal Content Here</p>
export default {
  name: 'Modal',
  data() {
    return {
      open: false,
  methods: {
    openModal() { = true
    closeModal() { = false

Download Details:

Author: phegman

Live Demo:

Download Link:

Official Website:

Install & Download:

# Yarn
$ yarn add v-scroll-lock

$ npm install v-scroll-lock --save

You Might Be Interested In:

Add Comment