New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for a v-on:resize event #1915
Comments
Do it in lifecycle hooks of your components: ready: function () {
window.addEventListener('resize', this.handleResize)
},
beforeDestroy: function () {
window.removeEventListener('resize', this.handleResize)
} |
@yyx990803 Sir I have this:
However if i resize the browser the height remains same |
You need to use an event handler on the window to listen to the resize event, as he's shown above. The code there sets the value This is what you'll want to do instead: // initialize data
data() {
return {
fullHeight: document.documentElement.clientHeight
}
},
// bind event handlers to the `handleResize` method (defined below)
ready: function () {
window.addEventListener('resize', this.handleResize)
},
beforeDestroy: function () {
window.removeEventListener('resize', this.handleResize)
},
methods: {
// whenever the document is resized, re-set the 'fullHeight' variable
handleResize (event) {
this.fullHeight = document.documentElement.clientHeight
}
} In your case, though... it seems like this style will work just as well, without needing to use the resize event at all. <div class="wrapper__Row" style="height: 100vh"></div> If you have any more questions, feel free to ask on the VueJS forums or on Gitter. |
What about store the target boundingClientRect (or anything else) and use a common resize event on window that loop through all request resize and compare current size and stored size, then do callback if needed... ? |
I thought a $forceUpdate would recalculate all computed properties within my component... Is this supposed to work, or am I thinking of this the wrong way? thx |
@eybarta I think you're doing it wrong. $forceUpdate can cost a lot. Why not use the event and a variable?
|
Did you try vue-resize? |
Use |
@pablohpsilva Thanks for that, simple and works really cool. |
Hey @pablohpsilva .. How ro listen width from a child component and pass to parent component element? |
Has anyone found a good way to debounce these types of events? Would really rather not have 15 events firing when a user resizes the screen. A little bit of debounce would go a long way |
@AdsonCicilioti What you could do is make your child component listen to its on resize event (you should take care of those events, remembering to remove them once your component is destroyed) and when the event is triggered, it $emits an event so the parent component can hear it and so something about it. |
@kidBrazil I'm using lodash.. but you can just find a stand-alone debounce, I use it like this
|
@kidBrazil what @eybarta said is exactly what I would do. But you have to consider if you really want to debounce the event. Depending on what you're build, the debounce events can give you trouble to compute something needed. |
@pablohpsilva Thanks! I will look into getting loadash added to the app. Cheers |
I`m trying to resize canvas using iframe, because canvas sizes are independent from DOM changes and can be changed only using script. Other elements can scale for more reasons: when window resizes, when neighbours change their sizes (independently from Vue and other frameworks). In current project I want to use canvas to draw an editable grid. The concept example is on JSFiddle. Thanks |
@kidBrazil If all you are looking for is a debounce function, adding all of lodash is kind of overkill. Here is the standalone debounce function I use - debounce |
That's cool, guys. Now I've following code: this.$window = $(window)
// something do
this.$window.trigger('resize') It works fine with jQuery. this.$window.dispatchEvent(new Event('resize')); But |
I might be wrong, but this is not the place @dobeerman7 . |
I know this is a closed issue, but for any future visitors, the MutationObserver api is probably the best way to handle this (https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver). I set it up as a mixin for any components that need to be resized based on the size of their children.
|
@aidangarza F.Y.I. For the integration with Vue.js, you can try the |
In App.vue:
In Store.js:
In Component.vue (parameter 'is_mobile' is reactive):
|
Locking as this thread is really old and many solutions have been provided to match all tastes 🙂 |
It would be nice if there was a built in way to handle resizing.
Ex:
The text was updated successfully, but these errors were encountered: