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

Description:

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
    },
  },
}

Download Details:

Author: phegman

Live Demo: https://v-scroll-lock.peterhegman.com/

Download Link: https://github.com/phegman/v-scroll-lock/archive/master.zip

Official Website: https://github.com/phegman/v-scroll-lock#demo

Last Update: November 18, 2019

Install:

# Yarn
$ yarn add v-scroll-lock

# NPM
$ npm install v-scroll-lock --save

You Might Be Interested In:

Add Comment