<!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>
<!-- 动态类class,布尔值是index是否相同;@click作用是index赋值 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 官方axios在线地址 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- <script src="vue.js"></script> -->
<style>
.isred {
color: red;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in arr" :class="{isred:currentIndex===index}" @click="change(index)">{{item}}</li>
</ul>
</div>
<script>
var area = new Vue({
el: "#app",
data: {
arr: ["还望", "海尔兄弟", "火影忍者"],
currentIndex: 0
},
methods: {
change: function(index) {
this.currentIndex = index;
}
}
});
</script>
</body>
</html>
【VUE】点击列表某一项,该项文字变成红色(currentIndex: 0经常用)
原文:https://www.cnblogs.com/icemiaomiao3/p/14659832.html