data: () => ({
active: null,
}),
<div class="item" v-for="i in 5">
<div class="parent" @click="active = active === i ? null : i">
<div class="child" :class="active === i ? 'green' : 'red'">{{ i }}</div>
</div>
</div>
data: () => ({
items: Array(5).fill(false),
}),
<div class="item" v-for="(n, i) in items">
<div class="parent" @click="$set(items, i, !n)">
<div class="child" :class="{ green: n, red: !n }">{{ i + 1 }}</div>
</div>
</div>
props: [ 'text' ],
data: () => ({
active: 0,
}),
<div class="item">
<div class="parent" @click="active ^= 1">
<div class="child" :class="[ 'red', 'green' ][active]">{{ text }}</div>
</div>
</div>
data: () => ({
items: Array.from({ length: 5 }, (_, i) => `item #${-~i}`),
}),
<v-item v-for="n in items" :text="n"></v-item>