vue點選列表變亮(v-for和v-bind的結合)
阿新 • • 發佈:2021-02-13
技術標籤:# Vue
v-for和v-bind的結合
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.red{
color: red;
}
ul li{
cursor: pointer;
}
</style>
</head>
<body>
<div id="app">
<ul>
<!--<li v-for="(item,index) in movies">{{index}}-{{item}}</li>-->
<li :class="{red:i === index}" v-for="(item,index) in movies" @click ="go(index)">{{item}}</li>
</ul>
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
movies: ['海王','海爾兄弟','火隱忍者','進擊的巨人'],
i: -1
},
methods:{
go:function (index) {
this.i = index
}
}
})
</script>
</body>
</html>
效果