<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### wx.request(OBJECT) OBJECT參數說明: ![](https://box.kancloud.cn/e54561740d6f242dcdf96da92a3815af_961x525.png) success返回參數說明: ![](https://box.kancloud.cn/246f757a4dad31ac07ba7f068de9c5b7_964x222.png) data 數據說明: 最終發送給服務器的數據是 String 類型,如果傳入的 data 不是 String 類型,會被轉換成 String 。轉換規則如下: 對于 header['content-type'] 為 application/json 的數據,會對數據進行 JSON 序列化 對于 header['content-type'] 為 application/x-www-form-urlencoded 的數據,會將數據轉換成 query string (encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...) 示例代碼: //獲取應用實例 var app = getApp() Page({ data: { indicatorDots:true, autoplay:true, interval:5000, duration:1000, banner: [] }, onLoad: function () { var that = this //調用應用實例的方法獲取全局數據 reda(this,'banner'); } }) function reda(_self,type){ wx.request({ url: 'http://127.0.0.1/demo/demo.php?type='+type, //僅為示例,并非真實的接口地址 header: { 'content-type': 'application/json' }, success: function(res) { console.log(res.data); _self.setData({ "banner":res.data.results, }); } }) } 返回值: ## 接口規則: 使用PHP來傳送數據,轉換為json數據: <?php if(!isset($_GET['id']) || empty($_GET['id'])) { echo jsonFormat(array('error_code'=>300,'info'=>'請求失敗')); } if($_GET['id']=='1') { $detail = array( 'id'=>'1', 'title'=>"詳情1", 'img'=>"http://*******.jpg", 'content'=>"框架的視圖層" ); } $detail = array('error_code'=>200,'results'=>$detail); echo json_encode($detail); ?> 基礎庫 1.4.0 開始支持,低版本需做兼容處理 返回一個 requestTask 對象,通過 requestTask,可中斷請求任務。 requestTask 對象的方法列表: ![](https://box.kancloud.cn/1f7b79bc251f76fd0cb975d92ce01a99_960x102.png) 示例代碼: const requestTask = wx.request({ url: 'test.php', //僅為示例,并非真實的接口地址 data: { x: '' , y: '' }, header: { 'content-type': 'application/json' }, success: function(res) { console.log(res.data) } }) requestTask.abort() // 取消請求任務 Bug & Tip tip: content-type 默認為 'application/json'; tip: url 中不能有端口; bug: 開發者工具 0.10.102800 版本,header 的 content-type 設置異常; 使用setData需注意 ![](https://box.kancloud.cn/4b08c382c10b01f184be65c6dd621e7a_903x663.png) 商品分類功能 示例: 有數據: ![](https://box.kancloud.cn/f098de781f2675d552f3e0502d7c3f99_381x668.png) 無數據: ![](https://box.kancloud.cn/57abc32ff1e9d171afaeb058907dcc9d_379x667.png) logs.js Page({ data: { navLeftItems: [], navRightItems: [], curNav: 1, curIndex: 0 }, onLoad: function () { // 加載的使用進行網絡訪問,把需要的數據設置到data數據對象 var that = this wx.request({ url: 'http://huanqiuxiaozhen.com/wemall/goodstype/typebrandList', method: 'GET', data: {}, header: { 'content-type': 'application/json' }, success: function (res) { console.log(res) that.setData({ navLeftItems: res.data, navRightItems: res.data }) } }) }, //事件處理函數 switchRightTab: function (e) { console.log(e); // 獲取item項的id,和數組的下標值 let id = e.target.dataset.id, index = parseInt(e.target.dataset.index); // 把點擊到的某一項,設為當前index this.setData({ curNav: id, curIndex: index }) } }) ## 模版調用: logs.wxml <!--主盒子--> <view class="container"> <!--左側欄--> <view class="nav_left"> <block wx:for="{{navLeftItems}}"> <!--當前項的id等于item項的id,那個就是當前狀態--> <!--用data-index記錄這個數據在數組的下標位置,使用data-id設置每個item的id值,供打開2級頁面使用--> <view class="nav_left_items {{curNav == item.id ? 'active' : ''}}" bindtap="switchRightTab" data-index="{{index}}" data-id="{{item.id}}">{{item.tree.desc}}</view> </block> </view> <!--右側欄--> <view class="nav_right"> <!--如果有數據,才遍歷項--> <view wx:if="{{navRightItems[curIndex].tree.nodes[1].tree.nodes}}"> <block wx:for="{{navRightItems[curIndex].tree.nodes[1].tree.nodes}}"> <view class="nav_right_items"> <navigator url="../list/index?brand={{item.tree.id}}&typeid={{navRightItems[curIndex].id}}"> <!--用view包裹圖片組合,如果有圖片就用,無圖片提供就使用50x30的這個默認圖片--> <view> <block wx:if="{{item.tree.logo}}"> <image src="{{item.tree.logo}}"></image> </block> <block wx:else> <image src="http://temp.im/50x30"></image> </block> </view> <!--如果有文字,就用文字;無文字就用其他--> <view wx:if="{{item.tree.desc}}"> <text>{{item.tree.desc}}</text> </view> <view wx:else> <text>{{item.tree.desc2}}</text> </view> </navigator> </view> </block> </view> <!--如果無數據,則顯示數據--> <view style='text-align:center' wx:else>暫無數據。。。</view> </view> </view> logs.wxss page{ background: #f5f5f5; } /*總體主盒子*/ .container { position: relative; width: 100%; height: 100%; background-color: #fff; color: #939393; } /*左側欄主盒子*/ .nav_left{ /*設置行內塊級元素(沒使用定位)*/ display: inline-block; width: 25%; height: 100%; /*主盒子設置背景色為灰色*/ background: #f5f5f5; text-align: center; } /*左側欄list的item*/ .nav_left .nav_left_items{ /*每個高30px*/ height: 30px; /*垂直居中*/ line-height: 30px; /*再設上下padding增加高度,總高42px*/ padding: 6px 0; /*只設下邊線*/ border-bottom: 1px solid #dedede; /*文字14px*/ font-size: 14px; } /*左側欄list的item被選中時*/ .nav_left .nav_left_items.active{ /*背景色變成白色*/ background: #fff; } /*右側欄主盒子*/ .nav_right{ /*右側盒子使用了絕對定位*/ position: absolute; top: 0; right: 0; flex: 1; /*寬度75%,高度占滿,并使用百分比布局*/ width: 75%; height: 100%; padding: 10px; box-sizing: border-box; background: #fff; } /*右側欄list的item*/ .nav_right .nav_right_items{ /*浮動向左*/ float: left; /*每個item設置寬度是33.33%*/ width: 33.33%; height: 80px; text-align: center; } .nav_right .nav_right_items image{ /*被圖片設置寬高*/ width: 50px; height: 30px; } .nav_right .nav_right_items text{ /*給text設成塊級元素*/ display: block; margin-top: 5px; font-size: 10px; /*設置文字溢出部分為...*/ overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看