I'm looping through elements and I'm positioning div using top and left CSS properties:
<div
v-for="coord in coords"
:style="{ top: coord.y + 'px', left: coord.x + 'px' }"
></div>
Sometimes instead of top property I need to use bottom (this depends on one of my Vuex store values). How can I dynamically define if I should use top or bottom CSS property?
I tried to used computed prop isTopOrBottom which would return 'top' or 'bottom: :style="{ isTopOrBottom: coord.y + 'px', left: coord.x + 'px' }". But this is not working in Vue.
<coord>and then define acomputed()property for the style. In the computed property, you can return an object depending on your conditions. Or - if you don't want to create a separate components - you could define a method and call it from the template. Then, pass the coords and return an object based on your conditions. Method calls are not cached like computed properties.