标题Vue之动态绑定CSS样式
效果图:
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
ul li {
list-style: none;
border: #ddd solid 1px;
width: 200px;
text-align: center;
margin: 10px;
box-shadow: 0 0 10px #ddd;
border-radius: 10px;
padding: 5px 0;
}
.active {
background-color: red;
color: aliceblue;
}
</style>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<ul>
<li :class={active:index==isActive} @click="checkItem(index)" v-for="(m,index) in movies">{{m}}---{{index}}</li>
</ul>
</div>
<script>
const app = new Vue({
el:'#app',
data:{
movies:['盗墓笔记','降魔的','斗罗大陆','火影忍者','二龙湖的爱情故事','老九门'],
isActive:-1,
},
methods:{
checkItem(index){
this.isActive=index;
}
}
})
</script>
</body>
</html>