发起请求

111 阅读1分钟

1. scroll-view

可滚动视图区域。使用竖向滚动时,需要给scroll-view一个固定高度,通过 WXSS 设置 height。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。

scroll-x:允许横向滚动。

scroll-y:允许纵向滚动。

<!-- 导入wxs文件 -->
<wxs src="../../wxs/filter.wxs" module="filter" />
<view class="container">
  <scroll-view scroll-y class="left">
    <view class="item {{activeIndex===index?'active':''}}" wx:for="{{typeList}}" wx:key="index" bindtap="clickType"
      data-index="{{index}}" data-id="{{item.Id}}">{{item.Name}}</view>
  </scroll-view>
  <scroll-view scroll-y class="right">
    <view class="data" wx:for="{{dataList}}" wx:key="index">
      <view class="title">{{item.Title}}</view>
      <view class="flex j-s a-c" style="padding:4px 0; color:#333333">
        <view>{{item.Section.Name}}</view>
        <view>{{filter.formatTime(item.Createtime)}}</view>
      </view>
    </view>
  </scroll-view>
</view>

2. 发起请求

//显示Loading
wx.showLoading({
    title: '加载中',
})
//wx对象发送ajax请求的方法
wx.request({
    method:'GET',
    url: 'https://bingjs.com:8002/Subject/GetSubjects',
    data:{
        section_id:id
    },
    //成功后的回调
    success:({data})=>{
        //将获取到数据数据赋值给对应的数组,并更新到页面
        this.setData({
            dataList:data
        })
    },
    //完成后的回调
    complete:()=>{
        //关闭Loading
        wx.hideLoading()
    }
})