vue實(shí)現(xiàn)按鈕切換圖片
本文實(shí)例為大家分享了vue實(shí)現(xiàn)按鈕切換圖片的具體代碼,供大家參考,具體內(nèi)容如下
Tab選項(xiàng)卡
實(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue鼠標(biāo)滾輪滾動(dòng)切換路由效果的實(shí)現(xiàn)方法
- vue實(shí)現(xiàn)滾動(dòng)鼠標(biāo)滾輪切換頁面
- vue使用swiper實(shí)現(xiàn)左右滑動(dòng)切換圖片
- 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)文章
vue 頁面跳轉(zhuǎn)的實(shí)現(xiàn)方式
這篇文章主要介紹了vue 頁面跳轉(zhuǎn)的實(shí)現(xiàn)方式,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下2021-01-01Vue?Router?返回后記住滾動(dòng)條位置的實(shí)現(xiàn)方法
使用?Vue?router?創(chuàng)建?SPA(Single?Page?App),往往有這種需求:首頁是列表頁,點(diǎn)擊列表項(xiàng)進(jìn)入詳情頁,在詳情頁點(diǎn)擊返回首頁后,希望看到的是,首頁不刷新,并且滾動(dòng)條停留在之前的位置,這篇文章主要介紹了Vue?Router?返回后記住滾動(dòng)條位置的實(shí)現(xiàn)方法,需要的朋友可以參考下2023-09-09Vue設(shè)置提示和警告彈出框?qū)崙?zhàn)案例
頁面中會(huì)有很多時(shí)候需要彈窗提示,下面這篇文章主要給大家介紹了關(guān)于Vue設(shè)置提示和警告彈出框的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02vue實(shí)現(xiàn)編輯器鍵盤抬起時(shí)內(nèi)容跟隨光標(biāo)距頂位置向上滾動(dòng)效果
這篇文章主要介紹了vue實(shí)現(xiàn)編輯器鍵盤抬起時(shí)內(nèi)容跟隨光標(biāo)距頂位置向上滾動(dòng)效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05