微信小程式-tab選項卡
阿新 • • 發佈:2019-01-02
目的:tab選項卡
知識點:
1、flex佈局;
2、資料繫結;
3、條件渲染;
4、列表渲染;
5、事件;
第一步:設定json資料
由於都是自己本地寫,沒用介面資料,所以在data裡面自己寫了一個數據:
data:{ "tabView":[ { "id": 10001, "title": "優酷視訊", "tree":[ { "id": 10001001, "title": "優酷綜藝" }, { "id": 10001002, "title": "優酷電影" }, { "id": 10001003, "title": "優酷電視劇" } ] }, { "id": 10002, "title": "騰訊視訊", "tree": [ { "id"總共三個類別的資料,curNavIndex是判斷點選切換時用的。
第二步:寫wxml程式碼
第三步:完善js程式碼
tabNavChange:function(res){ var that = this; console.log(res.target.dataset.index); console.log(res.target.dataset.id); let index = res.target.dataset.index; that.setData({ curNavIndex: index }) }
也就加了一個點選事件
第四步:wxss程式碼
.tabNavs{ display: flex; flex-direction: row; } .tabNavItem{ flex: 1; background: #fff; color: #000; text-align: center; font-size: 16px; line-height: 40px; border-bottom: 1px solid #000; } .active{ background: yellowgreen; border-bottom-color: gold; } .tabContentItem{ background: #dedede; margin: 10px 0; }tips:沒有怎麼具體去修飾頁面,各位大神不要嫌棄,有什麼問題請隨時聯絡我
另提供這個demo的原始碼地址:https://gitee.com/HeiMiaoZhongXiao/wxTab