标签:dex oct dev scale v-for ini fun this type
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue点击列表切换颜色</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<style>
.active {
color: red;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item, index) in items"
@click="handleClick(index)"
:class="{active: currentIndex === index}"
>
{{item}}
</li>
</ul>
</div>
<script>
const app = new Vue({
el:"#app",
data: {
items: ["随笔","文章","日记","评论"],
currentIndex: 0
},
methods: {
handleClick: function(index) {
this.currentIndex = index;
}
}
})
</script>
</body>
</html>
标签:dex oct dev scale v-for ini fun this type
原文地址:https://www.cnblogs.com/qjuly/p/13376609.html