Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
vue-window-size
Advanced tools
Provides reactivity window size properties for Vue.js. Supports Vue.js v3.x and v2.7 or higher.
The following command installs vue-window-size v2.
$ yarn add vue-window-size
// or
$ npm i vue-window-size
Note: For use with v2.6, see here.
Composition API or Plugin or Mixin.
Composition API | Plugin | Mixin | |
---|---|---|---|
has window sizes properties | only in use | all components | only in use |
handle resize event | only in use | all times | all times |
Use with component.
<script lang="ts">
import { defineComponent } from 'vue';
import { useWindowSize } from 'vue-window-size';
export default defineComponent({
setup() {
const { width, height } = useWindowSize();
return {
windowWidth: width,
windowHeight: height,
};
},
});
</script>
<template>
<div>
<p>window width: {{ windowWidth }}</p>
<p>window height: {{ windowHeight }}</p>
</div>
</template>
note: useWindowSize handles a Resize Event only when it is in use. Even if it is called by multiple components, the Resize event is processed only once. If it is not used, it will not be handled.
Install plugin
import { createApp } from 'vue';
import App from "./App.vue"; // your App component
import { VueWindowSizePlugin } from 'vue-window-size/plugin';
const app = createApp(App);
app.use(VueWindowSizePlugin);
Use with component
<template>
<div>
<p>window width: {{ $windowWidth }}</p>
<p>window height: {{ $windowHeight }}</p>
</div>
</template>
Use with component
<script lang="ts">
import { defineComponent } from 'vue';
import { vueWindowSizeMixin } from 'vue-window-size/mixin';
export default defineComponent({
mixins: [vueWindowSizeMixin()],
});
</script>
<template>
<div>
<p>window width: {{ $windowWidth }}</p>
<p>window height: {{ $windowHeight }}</p>
</div>
</template>
delay
(option)Number
33
Change delay time of resize event.
e.g.
import { createApp } from 'vue';
import App from "./App.vue"; // your App component
import { VueWindowSizePlugin } from 'vue-window-size/plugin';
const app = createApp(App);
app.use(VueWindowSizePlugin, {
delay: 100,
});
config(config: VueWindowSizeOptionApiConfig)
Same as config for Option API.
import { vueWindowSizeAPI } from 'vue-window-size/plugin'; // or 'vue-window-size/mixin'
vueWindowSizeAPI.config({
delay: 100,
});
init()
Initialize the plugin. Usually called automatically. Please call it if you want to use it again after destroy.
import { vueWindowSizeAPI } from 'vue-window-size/plugin'; // or 'vue-window-size/mixin'
vueWindowSizeAPI.init();
destroy()
Remove the resize event.
import { vueWindowSizeAPI } from'vue-window-size/plugin'; // or 'vue-window-size/mixin'
vueWindowSizeAPI.destroy();
useWindowSize
is a singleton and handles the resize event.
Therefore, using useWindowSize(config)
will affect all components in used.
Due to the nature of the Composition API, this is not the desired behavior.
I also think that there are not many use cases that need to be set individually.
If requested, I will create a useAtomicWindowSize(config)
that can be set atomically, so please create an issue.
Or create a factory function for createUseWindowSize(config)
.
vue-window-size adds addEventListener only once, even if it is used in mixin. So basically you do not need to call removeEventListener. If you want to call removeEventListener please call destroy method.
If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.
FAQs
Reactivity window size for Vue.js.
The npm package vue-window-size receives a total of 4,040 weekly downloads. As such, vue-window-size popularity was classified as popular.
We found that vue-window-size demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.