Vue實現(xiàn)點擊顯示不同圖片的效果
更新時間:2019年08月10日 08:50:40 作者:潔19
這篇文章主要為大家詳細介紹了Vue實現(xiàn)點擊顯示不同圖片的效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue點擊顯示不同圖片的具體代碼,供大家參考,具體內(nèi)容如
使用Vue中的以下知識點來顯示效果
①:v-for:循環(huán)遍歷數(shù)據(jù)
②:v-bind:class={ }:綁定樣式
③:v-on:click(簡寫@click):點擊事件
④:v-if:判斷
<!DOCTYPE html>
<html>
<head>
<title>點擊顯示相對應的圖片</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style: none;
}
.myul{
display: flex;
}
.myul li{
border: 1px solid orange;
height: 150px;
width: 150px;
flex-direction: row;
text-align: center;
line-height: 150px;
}
.content{
border: 1px solid grey;
height: 350px;
width: 600px;
}
.content img{
height: 350px;
width: 600px;
}
.active{
background: #3A9ffb;
color: white;
}
</style>
</head>
<body>
<div class="app">
<div class="title">
<ul class="myul">
<li v-for="(item,index) in mess" v-bind:class="{ 'active': status === index}" v-on:click="changeImg(index)">
{{item.content}}
</li>
</ul>
</div>
<div class="content">
<img src="img/1.jpg" v-if="status === 0">
<img src="img/2.jpg" v-if="status === 1">
<img src="img/84.jpg" v-if="status === 2">
<img src="img/85.jpg" v-if="status === 3">
</div>
</div>
</body>
</html>
<script src="https://cdn.bootcss.com/vue/2.5.20/vue.js"></script>
<script type="text/javascript">
new Vue({
el:".app",
data:{
status:0, //狀態(tài)顯示
mess:[
{id:0,content:"點擊顯示圖片一"},
{id:1,content:"點擊顯示圖片二"},
{id:2,content:"點擊顯示圖片三"},
{id:3,content:"點擊顯示圖片四"}
]
},
methods:{
changeImg:function(index){
this.status=index;
}
}
})
</script>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Vue-admin-template?報Uncaught?(in?promise)?error問題及解決
這篇文章主要介紹了Vue-admin-template?報Uncaught?(in?promise)?error問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
詳解vuejs中執(zhí)行npm run dev出現(xiàn)頁面cannot GET/問題
這篇文章主要介紹了詳解vuejs中執(zhí)行npm run dev出現(xiàn)頁面cannot GET/問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-04-04

