Issue
I want to define the top property of a v-img depending on the current breakpoint of the window.
I wanted to define it like that:
<v-img contain id="logo-transparent" :top="logoTop" :width="logoWidth" :src="logoTransparent" class="hidden-xs-only"></v-img>
with the computed property looking like that:
logoTop(){
switch (this.$vuetify.breakpoint.name) {
case 'xl': return "-4%"
case 'lg': return "-6%"
case 'md': return "-8%"
case 'sm': return "-8%"
case 'xs': return 0
default:
return "-4%"
}
},
and the CSS like this:
#logo-transparent{
z-index: 1;
width: 400px;
height: 300px;
position: absolute;
right: -1%;
}
but the problem is that v-img doesn't have the top property.
I wanted to use my computed function to define the CSS of the image like this:
logoTop(){
return {
"--top-property" : switch (this.$vuetify.breakpoint.name) {
case 'xl': return 400
case 'lg': return 300
case 'md': return 300
case 'sm': return 200
case 'xs': return 0
default:
return 400
}
}
},
to be able to use it like this in the css:
top : var(--top-property)
but it seems that I can't use a switch in that case.
How could I do it?
Solution
switch
doesn't return anything. You should use a variable like so
logoTop() {
let topProperty;
switch (this.$vuetify.breakpoint.name) {
case 'xl':
topProperty = 400;
break;
case 'lg':
case 'md':
topProperty = 300;
break;
case 'sm':
topProperty = 200;
break;
case 'xs':
topProperty = 0;
break;
default:
topProperty = 400;
}
return {
"--top-property" : topProperty
}
},
Answered By - Cedric Cholley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.