<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<ul>
<li v-for="(m, index) in movies"
:class="{actived: activeItem === index}"
@click="clickOnLi(index)">{{index}}-{{m}}</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
activeItem: 0,
movies: ['犬夜叉', '火影忍者', '天是红河岸', '蓝色妖姬']
},
methods: {
clickOnLi: function(index) {
this.activeItem = index;
console.log(this.activeItem);
}
}
})
</script>
<style>
.actived {
background-color: greenyellow;
width: fit-content;
}
</style>
</body>
</html>
网友评论