I can't get attribute css of class in Vuejs/nuxtjs in my project.
My class: 'only-small' has attribute: 'display:none' if mediaquery <768.
If this way is impossible, can someone suggest another method to resolve my problem without using window object (window.innerWidth always error if refesh page - window is not defined) and vue-screen plugin
size.vue :
in viewport < 768
<button class="select-btn select-btn--size only-small">
<span class="select-btn__label"></span>
<svg class="icon icon--down">
<use xlink:href="/global.svg#down"></use>
</svg>
</button>
in viewport >= 768
<div class="select size-select small-font only-large size-select--small">
<div class="select__headline"></div>
<div class="select__items no-scrollbar">
<div>
<button class="select__label" ></button>
</div>
</div>
</div>
info.vue
<template>
<div>
<Size></Size>
<AddToCart></AddToCart>
</div>
</template
scss:
@media screen and (min-width: 768px) {
.only-small {
display: none !important;
}
}
- click add to cart with viewport < 768: do some action
- click add to cart with viewport > 768: do some other action
When I resize the viewport, no class, element,... is added or removed. Only attribute of css applies.
.only-smallelements to hide them? If so, you can use vue-mq (digitalocean.com/community/tutorials/vuejs-vue-media-queries) to help with your conditional rendering.