1. vue-resize
Detects DOM element resizing
vue-resize
Package: vue-resize
Created by: Akryum
Last modified: Tue, 28 Jun 2022 20:12:48 GMT
Version: 1.0.1
License: MIT
Downloads: 2,457,043
Repository: https://github.com/Akryum/vue-resize

Install

npm install vue-resize
yarn add vue-resize

vue-resize

npm npm
vue2

Detect DOM element resizing

JSFiddle

Become a Patreon

Sponsors

sponsors logos


Installation

npm install --save vue-resize

Module import

⚠️ You need to include the package CSS:

 import 'vue-resize/dist/vue-resize.css'

Then import the package and install it into Vue:

 import Vue from 'vue'
import VueResize from 'vue-resize'

Vue.use(VueResize)

Or:

 import Vue from 'vue'
import { ResizeObserver } from 'vue-resize'

Vue.component('resize-observer', ResizeObserver)

Browser

 <link rel="stylesheet" href="vue-resize/dist/vue-resize.css"/>

<script src="vue.js"></script>
<script src="vue-resize/dist/vue-resize.min.js"></script>

The plugin should be auto-installed. If not, you can install it manually:

 Vue.use(VueResize)

Or:

 Vue.component('resize-observer', VueResize.ResizeObserver)

Usage

Add the <resize-observer> inside a DOM element and make its position to something other than 'static' (for example 'relative'), so that the observer can fill it.

Listen to the notify event that is fired when the above DOM element is resized.

Example

 <template>
  <div class="demo">
    <h1>Hello world!</h1>
    <resize-observer @notify="handleResize" />
  </div>
</template>

<script>
export default {
  methods: {
    handleResize ({ width, height }) {
      console.log('resized', width, height)
    }
  }
}
</script>

<style scoped>
.demo {
  position: relative;
}
</style>

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin