admin_vue/03-v-bind动态属性绑定/练习1动态导航.html

67 lines
1.3 KiB
HTML
Raw Permalink Normal View History

2022-10-15 10:05:34 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动态导航</title>
<style>
*{
margin: 0;
padding: 0;
}
#nav{
text-align: center;
width: 100%;
margin-top: 20px;
}
div{
width: 100px;
height: 50px;
display: inline-block;
}
.item{
background-color: blueviolet;
line-height:50px ;
font-size: 18px;
font-weight: bolder;
border-radius: 10px;
margin: 0 10px;
}
.active{
background-color: skyblue;
}
[v-cloak]{
display: none;
}
</style>
</head>
<body>
<div id="nav" v-cloak>
<div :class="contents(index)" @click="change(index)" v-for="(items,index) in content" class="item">{{items}}</div>
</div>
</body>
2022-11-19 11:19:25 +08:00
<script src="../00-tools/JavaScript/vue.js"></script>
2022-10-15 10:05:34 +08:00
<script>
let vue=new Vue({
el:"#nav",
data:{
content:["首页","搜索","人文","新闻","法制","联系我们"],
isActive:true,
courseindex:-1,
},
methods: {
change:function(index){
this.courseindex=index
},
contents:function(index){
if(index==this.courseindex){
return {active:this.isActive}
}
}
},
})
</script>
</html>