vue實(shí)現(xiàn)按鈕切換圖片
本文實(shí)例為大家分享了vue實(shí)現(xiàn)按鈕切換圖片的具體代碼,供大家參考,具體內(nèi)容如下
Tab選項卡

實(shí)現(xiàn)步驟
1、實(shí)現(xiàn)靜態(tài)UI效果
用傳統(tǒng)的方式實(shí)現(xiàn)標(biāo)簽結(jié)構(gòu)和樣式
2、基于數(shù)據(jù)重構(gòu)UI效果
將靜態(tài)的結(jié)構(gòu)和樣式重構(gòu)為基于Vue模板語法的形式
處理事件綁定和js控制邏輯

設(shè)置基本樣式
{
overflow: hidden;
padding: 0;
margin: 0;
}
.tab ul li {
box-sizing: border-box;
padding: 0;
float: left;
width: 100px;
height: 45px;
line-height: 45px;
list-style: none;
text-align: center;
border-top: 1px solid #ccc;
border-right: 1px solid #ccc;
cursor: pointer;
}
.tab ul li.active {
background-color: orange;
}
.tab ul li:first-child {
border-left: 1px solid blue;
}
.tab div {
width: 500px;
height: 300px;
display: none;
text-align: center;
font-size: 30px;
line-height: 300px;
border: 1px solid blue;
border-top: 0px;
}
.tab div.current {
display: block;
}
實(shí)現(xiàn)靜態(tài)布局
<div id="app">
<button v-on:click="handla">向前切換</button>
<button v-on:click="handlc">單向循環(huán)切換</button>
<button v-on:click="handle">向后切換</button>
<div class="tab">
<ul>
<li :class="currentIndex==index?'active':''" :key="item.id" v-for="(item,index) in list">{{item.title}}
</li>
</ul>
<div :class="currentIndex==index?'current':''" :key="item.id" v-for="(item,index) in list">
<img :src="item.path">
</div>
</div>
</div>
實(shí)現(xiàn)具體功能
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript">
/* */
var vm = new Vue({
el: '#app',
data: {
currentIndex: 0,
list: [{
id: 1,
title: 'apple',
path: 'img/apple.png'
}, {
id: 2,
title: 'orange',
path: 'img/orange.png'
}, {
id: 3,
title: 'lemon',
path: 'img/lemon.png'
}]
},
methods: {
handle: function () {
if (this.currentIndex < 2) {
this.currentIndex = this.currentIndex + 1
}
},
handla: function () {
if (this.currentIndex > 0) {
this.currentIndex = this.currentIndex - 1
}
},
handlc: function () {
this.currentIndex = this.currentIndex + 1
if (this.currentIndex > 2) {
this.currentIndex = 0
}
},
}
})
</script>
最終效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue鼠標(biāo)滾輪滾動切換路由效果的實(shí)現(xiàn)方法
- vue實(shí)現(xiàn)滾動鼠標(biāo)滾輪切換頁面
- vue使用swiper實(shí)現(xiàn)左右滑動切換圖片
- vue自定義js圖片碎片輪播圖切換效果的實(shí)現(xiàn)代碼
- vue實(shí)現(xiàn)圖片切換效果
- Vue實(shí)現(xiàn)base64編碼圖片間的切換功能
- vue卡片式點(diǎn)擊切換圖片組件使用詳解
- Vue實(shí)現(xiàn)簡單圖片切換效果
- vue+js點(diǎn)擊箭頭實(shí)現(xiàn)圖片切換
- Vue實(shí)現(xiàn)鼠標(biāo)懸浮切換圖片src
相關(guān)文章
vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的示例代碼
這篇文章主要介紹了vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的操作,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01
vue?頁面卡死,點(diǎn)擊無反應(yīng)的問題及解決
這篇文章主要介紹了vue?頁面卡死,點(diǎn)擊無反應(yīng)的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10
淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題
今天小編就為大家分享一篇淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題,具有很好的價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
Vue2.0仿餓了么webapp單頁面應(yīng)用詳細(xì)步驟
本篇文章給大家分享了Vue2.0仿餓了么webapp單頁面應(yīng)用詳細(xì)步驟,有興趣的朋友可以跟著操作下。2018-07-07

