简体   繁体   English

VueJs - 在窗口调整大小时添加类

[英]VueJs - Add class on window resize

Using Vuejs, what is the correct way to add and remove a class depending on what size the browser window is?使用 Vuejs,根据浏览器窗口的大小添加和删除类的正确方法是什么?

I've been looking at 'v-transitions', however, all the examples I have come across are using an on click event.我一直在研究“v-transitions”,但是,我遇到的所有示例都使用了点击事件。

I think that the best option is to add a native window event listener on component mounted and manage classes depending on dimensions.我认为最好的选择是在已安装的组件上添加本机窗口事件侦听器,并根据尺寸管理类。
Then you might use :class="..." binding ( https://v2.vuejs.org/v2/guide/class-and-style.html ) in your template and pass an array of classes there.然后你可以在你的模板中使用:class="..."绑定( https://v2.vuejs.org/v2/guide/class-and-style.html )并在那里传递一个类数组。
Look at this fiddle for a very close example https://jsfiddle.net/hr77p7qb/3/看看这个小提琴的一个非常接近的例子https://jsfiddle.net/hr77p7qb/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM