1.用v-bind切換圖片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- u-bind:綁定一個屬性,簡寫 :屬性名=""-->
<div class="itany">
<img v-bind:src="url" v-on:click="atl">
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
el:".itany",
data:{
url:"img/a.jpg",
flag:true
},
methods:{
atl:function(){
if(this.flag){
this.url="img/b.jpg";
this.flag=false;
}
else{
this.url="img/a.jpg";
this.flag=true;
}
}
}
})
</script>
</body>
</html>
2.用v-show制作選項卡
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
padding: 0px;
margin: 0px;
}
ul{
overflow: hidden;
}
li{
float: left;
width: 60px;
border: 1px solid black;
text-align: center;
list-style: none;
cursor: pointer
}
</style>
</head>
<body>
<div class="itany">
<img v-bind:src="url" v-on:click="alt">
<ul>
<li v-for="(val,index) in list" v-on:click="alt(index)">{{index+1}}</li>
</ul>
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
el:".itany",
data:{
url:"img/img8.jpg",
list:["img/img8.jpg","img/img9.jpg","img/img10.jpg","img/img11.jpg","img/img12.jpg"]
},
methods:{
alt:function(ind){
this.url=this.list[ind]
}
}
})
</script>
</body>
</html>
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者