Vue可自定義tab組件用法實(shí)例
在工作中我們常常要用到tab組件,如果有用第三方組件庫(kù)的話一般都會(huì)有這個(gè)組件,但如果沒有使用第三方組件庫(kù),或者想要自定義tab,那么或許這個(gè)無依賴的tab組件將會(huì)極大地節(jié)約你的開發(fā)時(shí)間。
如何使用?
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. 啟動(dòng)Vue Cli的serve,即可看到成果。
整個(gè)組件的設(shè)計(jì)思路借鑒了flutter的tabs組件,數(shù)據(jù)的渲染交由vue完成,之后的tab控制由TabController實(shí)例來完成。
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)知識(shí)點(diǎn)內(nèi)容,感謝大家的學(xué)習(xí)和對(duì)腳本之家的支持。
- vue實(shí)現(xiàn)tab路由切換組件的方法實(shí)例
- vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果
- Vue切換Tab動(dòng)態(tài)渲染組件的操作
- vue組件開發(fā)之tab切換組件使用詳解
- Vue render函數(shù)實(shí)戰(zhàn)之實(shí)現(xiàn)tabs選項(xiàng)卡組件
- 詳解vue2.0 使用動(dòng)態(tài)組件實(shí)現(xiàn) Tab 標(biāo)簽頁切換效果(vue-cli)
- Vue2.0 多 Tab切換組件的封裝實(shí)例
- vue.js移動(dòng)端tab組件的封裝實(shí)踐實(shí)例
- Vue.js組件tab實(shí)現(xiàn)選項(xiàng)卡切換
- Vue.js組件tabs實(shí)現(xiàn)選項(xiàng)卡切換效果
- vue封裝tabs組件案例詳解
相關(guān)文章
Vue使用axios進(jìn)行g(shù)et請(qǐng)求拼接參數(shù)的2種方式詳解
axios中post請(qǐng)求都是要求攜帶參數(shù)進(jìn)行請(qǐng)求,這篇文章主要給大家介紹了關(guān)于Vue使用axios進(jìn)行g(shù)et請(qǐng)求拼接參數(shù)的2種方式,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-01-01vue中g(shù)et和post請(qǐng)求的區(qū)別點(diǎn)總結(jié)
在本篇文章里小編給大家分享的是一篇關(guān)于vue中g(shù)et和post請(qǐng)求的區(qū)別點(diǎn)總結(jié)內(nèi)容,對(duì)此有興趣的朋友們可以跟著學(xué)習(xí)下。2021-12-12基于better-scroll 實(shí)現(xiàn)歌詞聯(lián)動(dòng)功能的代碼
BetterScroll 是一款重點(diǎn)解決移動(dòng)端(已支持 PC)各種滾動(dòng)場(chǎng)景需求的插件,BetterScroll 是使用純 JavaScript 實(shí)現(xiàn)的,這意味著它是無依賴的。本文基于better-scroll 實(shí)現(xiàn)歌詞聯(lián)動(dòng)功能,感興趣的朋友跟隨小編一起看看吧2020-05-05ElementUI中el-dropdown-item點(diǎn)擊事件無效問題
這篇文章主要介紹了ElementUI中el-dropdown-item點(diǎn)擊事件無效問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的方法
這篇文章主要給大家介紹了關(guān)于vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的相關(guān)資料,前端使用這個(gè)插件可以方便展現(xiàn)出json格式的數(shù)據(jù),下載引入使用代碼可直接使用,需要的朋友可以參考下2024-05-05vue中img src 動(dòng)態(tài)加載本地json的圖片路徑寫法
這篇文章主要介紹了vue中的img src 動(dòng)態(tài)加載本地json的圖片路徑寫法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04Vue2(三)實(shí)現(xiàn)子菜單展開收縮,帶動(dòng)畫效果實(shí)現(xiàn)方法
這篇文章主要介紹了vue實(shí)現(xiàn)收縮展開效果的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04