Vue点击哪个元素哪个元素发生变化
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.active{
color: red;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<ul>
<li
v-for="(item, index) in movies"
:class="{active: currentIndex === index}"
@click="changeInde(index)">
{{item}}
</li>
</ul>
</div>
<script>
const app = new Vue({
el:'#app',
data:{
movies:['我是药神', '飞出人生', '夏洛特烦恼'],
currentIndex: 0
},
methods:{
changeInde(index){
this.currentIndex = index
}
}
});
</script>
</body>
</html>