分类

<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({

  /**

  * 页面的初始数据

  */

  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);

    })

  },

  /**

  * 生命周期函数--监听页面加载

  */

  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);

      })

    })

  },

  /**

  * 生命周期函数--监听页面初次渲染完成

  */

  onReady: function () {

  },

  /**

  * 生命周期函数--监听页面显示

  */

  onShow: function () {

  },

  /**

  * 生命周期函数--监听页面隐藏

  */

  onHide: function () {

  },

  /**

  * 生命周期函数--监听页面卸载

  */

  onUnload: function () {

  },

  /**

  * 页面相关事件处理函数--监听用户下拉动作

  */

  onPullDownRefresh: function () {

  },

  /**

  * 页面上拉触底事件的处理函数

  */

  onReachBottom: function () {

  },

  /**

  * 用户点击右上角分享

  */

  onShareAppMessage: function () {

  }

})


    </scroll-view>

  </view>

</view>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容