Is it possible to achieve this with a dynamic class like the following?
<div :class="'outofstock.item_' + item.id ? 'bg-green-500' : 'bg-red-500' ">
I have been struggling to find the correct syntax for this. Thank you for any answers.
This is an example of what I am trying to accomplish. I need the result outofstock.item_1, outofstock.item_2, and outofstock.item_3 in the :class attribute.
<template>
<ul>
<li v-for="item in items">
<div :class="'outofstock.item_' + item.id ? 'bg-green-500' : 'bg-red-500' ">
{{ item.name }}
</div>
</li>
</ul>
</template>
<script>
export default {
data () {
return {
items: [{id: 1, name: 'monitor'}, {id: 2, name: 'printer'},{id: 3, name: 'scanner'],
outofstock: {item_1: false, item_2: true, item_3: false}
}
}
}
</script>