Socket
Socket
Sign inDemoInstall

vue3-v-resize

Package Overview
Dependencies
21
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue3-v-resize

Vue 3 resize observer with debounce


Version published
Maintainers
1
Created

Readme

Source

vue3-v-resize

version download languages license vue@3.x

Resize observer for Vue.
Detect size changes of DOM elements. Support Vue's directive and component.

  • Vue3 Live

Feature

  • 🕰 Based on ResizeObservable API implementation
  • 🎁 Support vue3
  • 💊 Support the use of directives or components
  • 🧲 Optimize the frequency of triggering resize events
  • 🛠 Support browsers: Edge/Chrome/Safari/Firefox

Install

npm

npm install vue3-v-resize

Usage

<template>
  <div id="app">
    <!-- directives -->
    <div v-resize:50.immediate="onResize">
      Listened to elements
    </div>
    
    <!-- Components -->
    <ResizeComponent @resize="onResize" :delay="100" :disabled="disabled">
      <div>Listened to elements</div>
    </ResizeComponent>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ResizeComponent, resizeDirective as vResize } from 'vue3-v-resize'

const disabled = ref(false)

function onResize({ width, height }, target) {
  console.log(target, width, height)
}
</script>

1. Global Configuration

// main.js
import Resizer from 'vue3-v-resize'

// vue@3.x
const app = createApp(App)
app.use(Resizer, {
  // Custom command names and component names
  directive: 'resize',
  component: 'ResizeComponent'
})

2. On demand

<script setup>
import { ref } from 'vue'
import {
  ResizeComponent,
  resizeDirective as vResizeObserver //You can change the directive name, the default: `v-resize, 
} from 'vue3-v-resize'

// OR
// import Resizer from 'v-resize-observer'
// const ResizeComponent = Resizer.component
// const vResize = Resizer.directive

function onResize({ width, height }, target) {
  console.log(target, width, height)
}
</script>

<template>
  <div id="app">
    <!-- directives -->
    <div v-resize-observer:100="onResize">
      Listened to elements
    </div>
    
    <!-- Components -->
    <ResizeComponent @resize="onResize">
      <div>Listened to elements</div>
    </ResizeComponent>
  </div>
</template>

立即执行一次callback

API

ParameterTypeDefaultDescription
targetstring, HTMLElement-Target elements to listen to
delaynumber150Delayed execution time
immediatebooleanfalseexecuted immediately
disabledbooleanfalsedisable listening
resizefunction-Callback function to listen for changes in element size

resize(data, target)

  • data : elements size { width, height }
  • target : Listening elements

use directive

The directive default name is v-resize, if you want to change it, you can specify it when you import it.

<div v-resize="onResize" />

<div v-resize:100="onResize" />
<div v-resize:100.immediate="onResize" />
<!-- No limit on trigger frequency -->
<div v-resize:0="onResize" />

Parameter:

  • arg: => delay
  • value: => resize
  • modifiers.immediate

use Component

<ResizeComponent target="#app" :delay="0" disabled="false" @resize="onResize">
  <div>Listened to elements</div>
</ResizeComponent>

props

  • target: The target element to listen to, the default current element.
  • delay: Delay execution time, default: 150.
  • immediate: Execute immediately, default: false.
  • disabled: disable listening, default: false.

events

  • resize: Triggered when listening for element size changes.

Keywords

FAQs

Last updated on 30 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc