<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.active {
color: orange;
}
</style>
</head>
<body>
<div id="app">
<ul>
<!--<li v-for="变量 in movies">{{变量}}</li>-->
<li v-for="(item, index) in movies" :key="index" :class="{active:index===currentIndex }" @click="changeColor(index)">{{index+"---"+item}}></li>
</ul>
</div>
<script src="../vuejs/vuejs/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
currentIndex: 0,
movies: ['悬崖上的金鱼公主', '龙猫', '千与千寻', '起风了'],
},
methods: {
changeColor(index) {
this.currentIndex = index
}
},
})
</script>
</body>
</html>
效果: