new Vue({ el: '#app', data: function() { return { titles: ['a', 'b', 'c'], highlightIndex: null } }, methods: { } })
<div id="app"> <div v-for="(title, index) in titles" class="title" @click="highlightIndex = index"> {{title}} <div class="highlight" v-if="index == highlightIndex"></div> </div> </div>
.title { width: 150px; background-color: #0099CC; margin: 10px 0; } .highlight { width: 50px; height: 50px; margin: 10px 0; background-color: #660000; }