分類

<view class="box">

? <view class="fenlei">

? ? <scroll-view scroll-y="true" style="height: 100vh;">

? ? ? <view class="{{countindex==index?'active':''}} fenlei-item" wx:for="{{categories}}" wx:key="index" wx:for-item="categories" bindtap="get" data-children="{{categories.children}}" data-index="{{index}}">

? ? ? ? {{categories.name}}

? ? ? </view>

? ? </scroll-view>

? </view>

? <view class="content">

? ? <scroll-view scroll-y="true" style="height: 100vh;">

? ? ? <view wx:for="{{categories}}" wx:key="index" wx:for-item="icon">

? ? ? ? <view wx:for="{{icon.children}}" wx:key="index" wx:for-item="list">

? ? ? ? ? <block wx:if="{{pid==icon.id}}">

? ? ? ? ? ? {{list.name}}

? ? ? ? ? </block>

? ? ? ? </view>

? ? ? </view>

.box {

? display: flex;

}

.fenlei {

? height: 100vh;

? background: #ccc;

}

.content {

? flex: 1;

? height: 100vh;

? background: red;

}

.fenlei-item {

? width: 100%;

? line-height: 150rpx;

? text-align: center;

? background-color: #F7F8FA;

? box-sizing: border-box;

? border-bottom: 1px dashed #ccc;

}

.active {

? border-left: 5px solid rgb(64, 180, 70);

? background: #ccc;

}

Page({

? /**

? * 頁面的初始數(shù)據(jù)

? */

? data: {

? ? categories: [],

? ? children: [],

? ? countindex: 0,

? ? pid: 1

? },

? get(e) {

? ? let index = e.currentTarget.dataset.index

? ? // console.log(e.currentTarget.dataset.id);

? ? // console.log(e.currentTarget.dataset.children);

? ? // console.log(e.currentTarget.dataset.index);

? ? if (this.data.countindex != index) {

? ? ? this.setData({

? ? ? ? countindex: index

? ? ? })

? ? }

? ? this.setData({

? ? ? children: e.currentTarget.dataset.children,

? ? })

? ? this.data.children.forEach(r => {

? ? ? this.setData({

? ? ? ? pid: r.pid

? ? ? })

? ? ? console.log(this.data.pid);

? ? })

? },

? /**

? * 生命周期函數(shù)--監(jiān)聽頁面加載

? */

? onLoad: function (options) {

? ? wx.request({

? ? ? method: 'GET',

? ? ? url: '路徑',

? ? ? header: {

? ? ? ? Authorization: wx.getStorageSync('token')

? ? ? },

? ? ? success: (res => {

? ? ? ? // console.log(res);

? ? ? ? this.setData({

? ? ? ? ? categories: res.data.categories

? ? ? ? })

? ? ? ? // console.log(res.data.categories);

? ? ? })

? ? })

? },

? /**

? * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成

? */

? onReady: function () {

? },

? /**

? * 生命周期函數(shù)--監(jiān)聽頁面顯示

? */

? onShow: function () {

? },

? /**

? * 生命周期函數(shù)--監(jiān)聽頁面隱藏

? */

? onHide: function () {

? },

? /**

? * 生命周期函數(shù)--監(jiān)聽頁面卸載

? */

? onUnload: function () {

? },

? /**

? * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作

? */

? onPullDownRefresh: function () {

? },

? /**

? * 頁面上拉觸底事件的處理函數(shù)

? */

? onReachBottom: function () {

? },

? /**

? * 用戶點(diǎn)擊右上角分享

? */

? onShareAppMessage: function () {

? }

})


? ? </scroll-view>

? </view>

</view>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容