Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useScrollLock.md
1---2category: Sensors3---45# useScrollLock67Lock scrolling of the element.89## Usage1011```vue12<script setup lang="ts">13import { useScrollLock } from '@vueuse/core'14import { useTemplateRef } from 'vue'1516const el = useTemplateRef('el')17const isLocked = useScrollLock(el)1819isLocked.value = true // lock20isLocked.value = false // unlock21</script>2223<template>24<div ref="el" />25</template>26```2728## Directive Usage2930```vue31<script setup lang="ts">32import { vScrollLock } from '@vueuse/components'3334const data = ref([1, 2, 3, 4, 5, 6])35const isLocked = ref(false)36const toggleLock = useToggle(isLocked)37</script>3839<template>40<div v-scroll-lock="isLocked">41<div v-for="item in data" :key="item">42{{ item }}43</div>44</div>45<button @click="toggleLock()">46Toggle lock state47</button>48</template>49```5051## Type Declarations5253```ts54/**55* Lock scrolling of the element.56*57* @see https://vueuse.org/useScrollLock58* @param element59*/60export declare function useScrollLock(61element: MaybeRefOrGetter<62HTMLElement | SVGElement | Window | Document | null | undefined63>,64initialState?: boolean,65): WritableComputedRef<boolean, boolean>66```67