亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序技巧之show內(nèi)容展示,上傳文件編碼問題

 更新時間:2017年01月23日 11:54:39   作者:扶桑木下  
這篇文章主要介紹了微信小程序技巧之show內(nèi)容展示,上傳文件編碼問題,具有一定的參考價值,有興趣的可以了解一下。

show內(nèi)容展示

嘗試用微信小程序的template組件實(shí)現(xiàn)。同時,嘗試頁面間轉(zhuǎn)跳時傳參,在目標(biāo)頁面引入模板文件實(shí)現(xiàn) 寫的更少,做的更多 篇幅有限詳細(xì)代碼此處省略

  <view class="show-warp">
    <block wx:for="{{discuss}}" wx:key="index">
      <template is="discuss" data="{{item}}"></template>
      <template is="discuss-reply" data="{{item}}"></template>
      <template is="discuss-more" data="{{item}}"></template>
    </block>
  </view>
  Page({
    data: {
      discuss: [],
      petAge: 0,
      reply: false,
      height: 20
    },
    onLoad: function(){
      util.dataList.call(this, {
        cb: util.petAge
      });
    }  
  });
  /*
   * 部分公共邏輯頁代碼
   */
  function list(option) {
    var opt = {
      url: option.url || 'https://api.zg5v.com/index.php/index/show/showindex',
      data: option.data || {
        uid: 148,
        num: option.pageNum || 0
      },
      update: option.update || false,
      cb: option.cb || false,
      func: option.func || false
    };
    // 數(shù)據(jù)列表
    var showList = [];
    var objDa = [];
    this.data.replyListArr = [];
    // 保存/修改 this指向
    var self = this;
    ajax({
      url: opt.url,
      data: opt.data,
      cb: function(res) {
        showList = res.data.data;
        // 統(tǒng)一格式
        if (!Array.isArray(showList) &&
          typeof showList === 'object') {
          // 計算評論發(fā)布時間
          showList.pl.forEach(function(e, i) {
            e.cp_chongbirth = e.cp_addtime * 1000;
            e.replyTime = opt.cb(e.cp_chongbirth, true);
          }, showList.pl);
          objDa.push(showList);
        } else {
          objDa = showList;
        }
        // 更新評論列表
        if (opt.update) {
          let da = res.data.data.pl,
            plDa = self.data.discuss,
            i = 0,
            j = 0,
            len = da.length,
            jLen = plDa.length;
          for (; j < jLen; j++) {
            for (; i < len; i++) {
              if (plDa[j].pl.length > 0) {
                plDa[j].pl.push(da[i]);
              }
            }
          }
          objDa = plDa;
          opt.update = !opt.update;
        }
        if (res.data.status === 1) {
          for (var i = 0, len = objDa.length; i < len; i++) {
            if (opt.cb && typeof opt.cb === 'function') {
              // 計算寵物年齡
              objDa[i].petAge = opt.cb(objDa[i].cp_chongbir ||
                objDa[i].cp_chongbirth);
            }
          }
          self.setData({
            discuss: objDa
          });
        } else if (res.data.status === 2 || res.data.status === 0) {
          self.onLoad();
        }
        objDa = [];
      }
    });
  }

上傳文件編碼問題(*)

header 里的數(shù)據(jù)在真機(jī)預(yù)覽的時候是無效的。那就嘗試改變編碼進(jìn)行傳輸,在uploadFile 的參數(shù)中加入

header: {“chartset”:”utf-8”}

或是

header: {"content-type":'application/x-www-form-urlencoded'}

需要改到 formData 中,嘗試將編碼數(shù)據(jù)加入formData,但僅僅傳輸了數(shù)據(jù),并沒有改變編碼.header有問題暫時找不到解決方案,所以編碼操作暫時只能手動進(jìn)行.在javascript 中,字符串編碼函數(shù)是 encodeURI, 在小程序中嘗試可以使用。所以,將代碼改為如下: 

  wx.uploadFile({
    url: 'Upload image server path (Must be secure https)',
    // 待上傳的圖片,由 chooseImage獲得
    filePath: tempFilePaths[0],
    name: 'file',
    // HTTP 請求中其他額外的 form data
    formData: {
      // city: '太原',
      city: encodeURI('太原'),
      // name: 'taiyan',
      name: encodeURI('taiyan') // 名稱
    }, 
    success: function(res) {
      console.log("success", res);
    },
    fail: function(res) {
      console.log("fail", res);
    }
  });

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論