Vue可自定義tab組件用法實例
在工作中我們常常要用到tab組件,如果有用第三方組件庫的話一般都會有這個組件,但如果沒有使用第三方組件庫,或者想要自定義tab,那么或許這個無依賴的tab組件將會極大地節(jié)約你的開發(fā)時間。
如何使用?
1. 首先先安裝:
npm i vue-cus-tabs -S
2. 在new vue之前引入樣式并use一下VueCusTab:
import 'vue-cus-tabs/style/index.css' import { installCusTabs } from 'vue-cus-tabs'; Vue.use(installCusTabs);
3. 在代碼中引入組件:
<CusTabWrap> <template v-slot:tabBar> <CusTabBar :style="{'height':'50px'}"> <CusTabItem v-for="item in tabItems" :key="item.title"> {{item.title}} </CusTabItem> </CusTabBar> </template> <template v-slot:tabContainer> <CusTabContainer> <CusTabContainerItem v-for="item in tabItems"> <ul> <li v-for="data in item.data"> {{data.title}} </li> </ul> </CusTabContainerItem> </CusTabContainer> </template> </CusTabWrap>
import { TabController } from 'vue-cus-tabs'; import Vue from 'vue' export default class Test extends Vue{ public tabItems = [ { title: '新聞', type: 'list', data: [{ img: '', title: 'list item title' }] }, { title: '視頻', type: 'block', data: [{ video: '', title: 'list item title' }] }, { title: '視頻1', type: 'block', data: [{ video: '', title: 'list item title' }] }, ]; public tabController?: TabController; public mounted() { // 創(chuàng)建控制器 this.tabController = new TabController({ data: this.tabItems, tabScroll: true, initIndex: 1 }); } }
4. 啟動Vue Cli的serve,即可看到成果。
整個組件的設(shè)計思路借鑒了flutter的tabs組件,數(shù)據(jù)的渲染交由vue完成,之后的tab控制由TabController實例來完成。
github: https://github.com/axel10/cus-tabs
npm: https://www.npmjs.com/package/vue-cus-tabs
在線演示:https://vue-cus-tabs-axel10.now.sh
以上就是本次介紹的相關(guān)知識點內(nèi)容,感謝大家的學(xué)習(xí)和對腳本之家的支持。
- vue實現(xiàn)tab路由切換組件的方法實例
- vue使用動態(tài)組件實現(xiàn)TAB切換效果
- Vue切換Tab動態(tài)渲染組件的操作
- vue組件開發(fā)之tab切換組件使用詳解
- Vue render函數(shù)實戰(zhàn)之實現(xiàn)tabs選項卡組件
- 詳解vue2.0 使用動態(tài)組件實現(xiàn) Tab 標(biāo)簽頁切換效果(vue-cli)
- Vue2.0 多 Tab切換組件的封裝實例
- vue.js移動端tab組件的封裝實踐實例
- Vue.js組件tab實現(xiàn)選項卡切換
- Vue.js組件tabs實現(xiàn)選項卡切換效果
- vue封裝tabs組件案例詳解
相關(guān)文章
Vue使用axios進(jìn)行g(shù)et請求拼接參數(shù)的2種方式詳解
axios中post請求都是要求攜帶參數(shù)進(jìn)行請求,這篇文章主要給大家介紹了關(guān)于Vue使用axios進(jìn)行g(shù)et請求拼接參數(shù)的2種方式,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-01-01vue中g(shù)et和post請求的區(qū)別點總結(jié)
在本篇文章里小編給大家分享的是一篇關(guān)于vue中g(shù)et和post請求的區(qū)別點總結(jié)內(nèi)容,對此有興趣的朋友們可以跟著學(xué)習(xí)下。2021-12-12基于better-scroll 實現(xiàn)歌詞聯(lián)動功能的代碼
BetterScroll 是一款重點解決移動端(已支持 PC)各種滾動場景需求的插件,BetterScroll 是使用純 JavaScript 實現(xiàn)的,這意味著它是無依賴的。本文基于better-scroll 實現(xiàn)歌詞聯(lián)動功能,感興趣的朋友跟隨小編一起看看吧2020-05-05ElementUI中el-dropdown-item點擊事件無效問題
這篇文章主要介紹了ElementUI中el-dropdown-item點擊事件無效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的方法
這篇文章主要給大家介紹了關(guān)于vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的相關(guān)資料,前端使用這個插件可以方便展現(xiàn)出json格式的數(shù)據(jù),下載引入使用代碼可直接使用,需要的朋友可以參考下2024-05-05vue中img src 動態(tài)加載本地json的圖片路徑寫法
這篇文章主要介紹了vue中的img src 動態(tài)加載本地json的圖片路徑寫法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04Vue2(三)實現(xiàn)子菜單展開收縮,帶動畫效果實現(xiàn)方法
這篇文章主要介紹了vue實現(xiàn)收縮展開效果的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04