Show content display of WeChat applets and encoding of uploaded files,

Source: Internet
Author: User

Show content display in applet skills, encoding of uploaded files,

Show content display

Try using the template component of the applet. At the same time, when you try to switch between pages, the parameter will be transferred, and the template file will be introduced to the target page to write less, and more space is required. The detailed code is omitted here.

  <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}) ;}});/** code of some public logic pages */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. fun C | false}; // data list var showList = []; var objDa = []; this. data. replyListArr = []; // save/modify this to var self = this; ajax ({url: opt. url, data: opt. data, cb: function (res) {showList = res. data. data; // unified format if (! Array. isArray (showList) & typeof showList === 'object') {// calculates the comment release time 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;} // update the comment list 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') {// calculate the pet age 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 = [] ;}}) ;}

Encoding of uploaded files (*)

The data in the header is invalid during the real machine preview. Then try to change the encoding for transmission and add it to the uploadFile parameter.

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

Or

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

You need to change to formData and try to add the encoding data to formData, but only the data is transmitted and the encoding is not changed. the solution cannot be found for the header, so the encoding operation can only be performed manually. in javascript, the string encoding function is encodeURI, which can be used in small programs. Therefore, change the code to the following:

Wx. uploadFile ({url: 'upload image server path (Must be secure https) ', // the image to be uploaded. Obtain the filePath: tempFilePaths [0], name: 'file', // other form data formData: {// city: 'taiyuan ', city: encodeURI ('taiyuan'), // name: 'taiany', name: encodeURI ('taiany') // name}, success: function (res) {console. log ("success", res) ;}, fail: function (res) {console. log ("fail", res );}});

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.