In Vue JS, the window size can be retrieved using the following method:
Create a data property to hold the window size.
data() {
return {
windowSize: {
width: window.innerWidth,
height: window.innerHeight
}
};
}
Add an event listener to the mounted hook to update the window size when it is resized.
mounted() {
window.addEventListener("resize", this.getWindowSize);
},
beforeDestroy() {
window.removeEventListener("resize", this.getWindowSize);
},
methods: {
getWindowSize() {
this.windowSize = {
width: window.innerWidth,
height: window.innerHeight
};
}
}
Use the windowSize
property wherever it is needed in the Vue component.
<template>
<div>
<p>Window Width: {{ windowSize.width }}</p>
<p>Window Height: {{ windowSize.height }}</p>
</div>
</template>
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-08 08:17:29 +0000
Seen: 19 times
Last updated: Jun 08 '23
What does the error "Bar 0; array size is too large, maximum size is 100000" mean?
How can the text size of the plot be enlarged using ggcuminc?
How can I transfer the dimensions of a ChartArea from one PowerPoint chart to another?
The size of the plot returned by df.hist() is not the desired one.
How can I sort products that have the size attribute available in stock in Woocommerce?
What is the appropriate size for App store screenshots on a 6.5" display?
How to provide Arduino input parameters of any size without creating a struct?