vue+elementUI實(shí)現(xiàn)點(diǎn)擊左右箭頭切換按鈕功能
原本是可以用el-tabs做的,就像下面的樣式,但是領(lǐng)導(dǎo)說(shuō)不行
最后用button和element里面的el-carousel(走馬燈)結(jié)合了一下
長(zhǎng)這樣 感覺(jué)還不錯(cuò) 可以自己改樣式
代碼如下:
<div class="drawer-carousel"> <el-carousel arrow="always" :loop="false" :initial-index="0" indicator-position="none" :autoplay="false" height="60px" :items-per-page="6"> <el-carousel-item v-for="(group, index) in Math.ceil(tabs.length / 6)" :key="index"> <div class="button-group"> <el-button v-for="(tab, tabIndex) in tabs.slice(index * 6, (index + 1) * 6)" :key="tabIndex" @click="handleClickReport(tab.reportCoreId)" size="medium"> <el-tooltip :content="tab.reportCoreName" :disabled="isShowTooltip" :open-delay="100" placement="top" effect="light"> <span class="span-ellipsis" @mouseover="mouseOver($event)">{{ tab.reportCoreName }}</span> </el-tooltip> </el-button> </div> </el-carousel-item> </el-carousel> </div>
解釋一下
arrow="always"
顯示左右箭頭,loop="false"
表示不循環(huán)滾動(dòng),indicator-position="none"
表示不顯示指示器,:autoplay="false"
表示不自動(dòng)播放,height="60px"
設(shè)置 Carousel 的高度,:items-per-page="6"
表示每頁(yè)顯示6個(gè)按鈕。
<el-carousel-item>
:這是 Carousel 的每一頁(yè), 用v-for
循環(huán)來(lái)生成足夠的 Carousel 頁(yè)面,存放所有的按鈕。Math.ceil(tabs.length / 6)
計(jì)算出需要多少頁(yè),每頁(yè)6個(gè)按鈕。
<el-button>
:用v-for
循環(huán)來(lái)生成每一頁(yè)中的6個(gè)按鈕。用tabs.slice(index * 6, (index + 1) * 6)
來(lái)選取每頁(yè)6個(gè)按鈕,確保在當(dāng)前頁(yè)面范圍內(nèi)顯示正確的按鈕。
一些css樣式
.drawer-carousel { padding: 10px 10px 0 0; position: relative; .button-group { margin: 0 20px 0 40px; white-space: nowrap; span { display: inline-block; width: 90px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } } } //按鈕樣式 .el-carousel__arrow--left, .el-carousel__arrow--right { font-size: 30px; color: #1C1C1C; } .el-carousel__arrow--left { left: 0px; } .el-carousel__arrow--right { right: 0; }
如果放六個(gè)超出了,就設(shè)置一下button不換行 再給里面的文字設(shè)置超出顯示省略號(hào)就好了
到此這篇關(guān)于vue+elementUI實(shí)現(xiàn)點(diǎn)擊左右箭頭切換按鈕功能的文章就介紹到這了,更多相關(guān)vue elementUI左右箭頭切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue不用window的方式如何刷新當(dāng)前頁(yè)面
這篇文章主要介紹了vue不用window的方式如何刷新當(dāng)前頁(yè)面,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11Vue使用Axios庫(kù)請(qǐng)求數(shù)據(jù)時(shí)跨域問(wèn)題的解決方法詳解
在 VUE 項(xiàng)目開(kāi)發(fā)時(shí),遇到個(gè)問(wèn)題,正常設(shè)置使用 Axios 庫(kù)請(qǐng)求數(shù)據(jù)時(shí),報(bào)錯(cuò)提示跨域問(wèn)題,那在生產(chǎn)壞境下,該去怎么解決呢?下面小編就來(lái)和大家詳細(xì)講講2024-01-01在vue中使用jsonp進(jìn)行跨域請(qǐng)求接口操作
這篇文章主要介紹了在vue中使用jsonp進(jìn)行跨域請(qǐng)求接口操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10淺析Vue下的components模板使用及應(yīng)用
這篇文章主要介紹了Vue下的components模板的使用及應(yīng)用,本文通過(guò)代碼介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11vue2.0基于vue-cli+element-ui制作樹(shù)形treeTable
這篇文章主要介紹了vue2.0基于vue-cli+element-ui制作樹(shù)形treeTable,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04ElementUI的this.$notify.close()調(diào)用不起作用的解決
本文主要介紹了ElementUI的this.$notify.close()調(diào)用不起作用的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08