vue+elementUI實現(xiàn)點擊左右箭頭切換按鈕功能
原本是可以用el-tabs做的,就像下面的樣式,但是領(lǐng)導(dǎo)說不行
最后用button和element里面的el-carousel(走馬燈)結(jié)合了一下
長這樣 感覺還不錯 可以自己改樣式
代碼如下:
<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)滾動,indicator-position="none"
表示不顯示指示器,:autoplay="false"
表示不自動播放,height="60px"
設(shè)置 Carousel 的高度,:items-per-page="6"
表示每頁顯示6個按鈕。
<el-carousel-item>
:這是 Carousel 的每一頁, 用v-for
循環(huán)來生成足夠的 Carousel 頁面,存放所有的按鈕。Math.ceil(tabs.length / 6)
計算出需要多少頁,每頁6個按鈕。
<el-button>
:用v-for
循環(huán)來生成每一頁中的6個按鈕。用tabs.slice(index * 6, (index + 1) * 6)
來選取每頁6個按鈕,確保在當(dāng)前頁面范圍內(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; }
如果放六個超出了,就設(shè)置一下button不換行 再給里面的文字設(shè)置超出顯示省略號就好了
到此這篇關(guān)于vue+elementUI實現(xiàn)點擊左右箭頭切換按鈕功能的文章就介紹到這了,更多相關(guān)vue elementUI左右箭頭切換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue使用Axios庫請求數(shù)據(jù)時跨域問題的解決方法詳解
在 VUE 項目開發(fā)時,遇到個問題,正常設(shè)置使用 Axios 庫請求數(shù)據(jù)時,報錯提示跨域問題,那在生產(chǎn)壞境下,該去怎么解決呢?下面小編就來和大家詳細講講2024-01-01淺析Vue下的components模板使用及應(yīng)用
這篇文章主要介紹了Vue下的components模板的使用及應(yīng)用,本文通過代碼介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11vue2.0基于vue-cli+element-ui制作樹形treeTable
這篇文章主要介紹了vue2.0基于vue-cli+element-ui制作樹形treeTable,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04ElementUI的this.$notify.close()調(diào)用不起作用的解決
本文主要介紹了ElementUI的this.$notify.close()調(diào)用不起作用的解決,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08