vue-resize-observer
Vue普通元素resize事件监听
148,954
63
| Install | |
|---|---|
npm install vue-resize-observer |
|
| Latest Version: | 2.0.16 |
| Vue: | 3 |
| Older releases: | 2 |
| License: | MIT |
| Last Updated: | Oct 29, 2021 |
| Links: | GitHub · npm |
Maintainer: dengfengwang
English | 简体中文

Installation
- Vue3.0
npm install --save vue-resize-observer@next
- Vue2.0
npm install --save vue-resize-observer
Module import & Example
- Import the package and install it into Vue:
const VueResizeObserver = require("vue-resize-observer");
// Vue3.0
const app = createApp(App)
app.use(VueResizeObserver) // use is a instance's method & be called before mount
app.mount('#app')
// Vue2.0
Vue.use(VueResizeObserver); // use is a static method
or
import VueResizeObserver from "vue-resize-observer";
Vue.use(VueResizeObserver);
// Vue3.0
const app = createApp(App)
app.use(VueResizeObserver) // use is a instance's method & be called before mount
app.mount('#app')
// Vue2.0
Vue.use(VueResizeObserver); // use is a static method
or
import VueResizeObserver from "vue-resize-observer";
// Vue3.0
Vue.createApp({
directives: { 'resize': VueResizeObserver },
})
// Vue2.0
new Vue({
directives: { 'resize': VueResizeObserver },
})
- Then
v-resizedirective to detect DOM resize events.
<template>
<div class="resize" v-resize="onResize">
width: {{width}}, height: {{height}}
</div>
</template>
<script>
export default {
data() {
return {
width: 0,
height: 0,
}
},
mounted() {
this.width = this.$el.offsetWidth;
this.height = this.$el.offsetHeight;
},
methods: {
onResize({ width, height }) {
this.width = width;
this.height = height;
}
}
}
</script>
<style>
.resize {
background-color: orange;
width: 300px;
height: 300px;
margin: 0 auto;
resize: both;
overflow: auto;
display: flex;
justify-content: center;
align-items: center;
}
</style>
Example
Documentation
npm run doc
Or read the documentation online
⚠️ Notice
Set the v-resize directive for a DOM element and make the element position to something other than 'static' (for example 'relative').
Dependency
License
Copyright (c) 2020-present, Wayne
Related Packages
vue-use-scroll-size-observer
Vue3 composable that provides a simple and efficient way to observe changes to e...
855
0
Version History
| Version | Released | License |
|---|---|---|
| 2.0.16 | MIT | |
| 2.0.15 | MIT | |
| 2.0.13 | MIT | |
| 2.0.12 | MIT | |
| 2.0.11 | MIT | |
| 2.0.10 | MIT | |
| 2.0.9 | MIT | |
| 2.0.8 | MIT | |
| 2.0.7 | MIT | |
| 2.0.6 | MIT | |
| 2.0.5 | MIT | |
| 2.0.3 | MIT | |
| 2.0.2 | MIT | |
| 2.0.1 | MIT | |
| 2.0.0 | MIT | |
| 1.0.37 | MIT | |
| 1.0.36 | MIT | |
| 1.0.35 | MIT | |
| 1.0.33 | MIT | |
| 1.0.32 | MIT | |
| 1.0.31 | MIT | |
| 1.0.30 | MIT | |
| 1.0.29 | MIT | |
| 1.0.28 | MIT | |
| 1.0.27 | MIT | |
| 1.0.26 | MIT | |
| 1.0.23 | MIT | |
| 1.0.22 | MIT | |
| 1.0.21 | MIT | |
| 1.0.15 | MIT |
Showing the latest 30 of 38. See every release on npm