欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 實例開發(fā)總結(jié)

 更新時間:2017年04月26日 14:40:21   投稿:lqh  
這篇文章主要介紹了微信小程序 開發(fā)過程中遇到問題總結(jié)的相關(guān)資料,需要的朋友可以參考下

微信小程序 開發(fā)過程中遇到問題總結(jié)

第一次正式開發(fā)一個小程序,就從以下幾個方面來談一談小程序的開發(fā)過程和心得吧,主要說說這次項目中用到的功能。

數(shù)據(jù)請求

這次的小程序,沒有太多的附加功能,所以數(shù)據(jù)以及對數(shù)據(jù)的處理是這次的主體工作,小程序向用戶提供API,供用戶向自己的服務(wù)器請求數(shù)據(jù),值得一提的是,開發(fā)小程序之前,需要先在微信公眾平臺申請appID,并且綁定域名,域名必須是https協(xié)議,然后在小程序的開發(fā)工具的配置信息中完善信息,請求的地址需要在前面綁定的域名下。這個項目中用到wx.request從服務(wù)器拉取數(shù)據(jù)。

wx.request({
   url: that.data.couponData.requestUrl,
   data: that.data.couponData.queryData,
   header: {
     'content-type': 'application/json'
   },
   success: function(res) {
     var list = res.data.goodsList;
     console.log(res.data);
     for(var i in list) {
       list[i].quanUsedNum = parseInt(list[i].quanTotalNum) - parseInt(list[i].quanRemainNum);
      list[i].isImgRendered = false;
     }
    list[0].isImgRendered = list[1].isImgRendered = list[2].isImgRendered = list[3].isImgRendered = true;
     that.setData({"couponData.totalPage":res.data.totalPage});
     that.setData({"couponData.list":that.data.couponData.list.concat(list)});
    that.setData({"couponData.loadmore":!that.data.couponData.loadmore});
     that.setData({"couponData.queryData.pageNum":parseInt(that.data.couponData.queryData.pageNum) + 1});
     if(that.data.couponData.queryData.pageNum > that.data.couponData.totalPage) {
      that.setData({"couponData.isAction":false});
    }

    if(that.data.couponData.list.length < 1) {
      that.setData({"couponData.nodata":true});
    }
     if(f) {
       f();
     }
   }
 });

數(shù)據(jù)緩存

這里使用數(shù)據(jù)緩存是因為需要做一個搜索功能,就涉及到頁面之間的數(shù)據(jù)傳遞,放在地址中也是一種方法,借用一下localStorage也可以,使用wx.setStorage將數(shù)據(jù)存儲到localStorage中,頁面跳轉(zhuǎn)之后,在從localStorage中讀取就可以了,讀取數(shù)據(jù)的時候分同步讀取和異步讀取。

剪切板的應(yīng)用

借用小程序的API可以很方便的將任何信息復(fù)制到剪切板,然后就可以粘貼了。

wx.setClipboardData({
   data: '【' + that.data.couponData.list[e.currentTarget.id].goodsTitle + '】復(fù)制這條信息,打開【手機淘寶】' + that.data.couponData.list[e.currentTarget.id].twoInOneKouling,
   success: function(res) {
     that.setData({"couponData.copyTip":true,"couponData.Kouling":that.data.couponData.list[e.currentTarget.id].twoInOneKouling})
   }
 });

模板

在這個項目中,頁面基本很相似,但有細(xì)微差別,所以就使用了模板,新建一個template/template.wxml,name屬性必須要設(shè)置。

 <template name='navsearch'>
 <view class='nav-search'>
   <view class='nav-search__container space-between'>
     <view class='nav-search__search' wx:if='{{isSearch}}'></view>
     <input class='nav-search__input' placeholder='請輸入關(guān)鍵詞找券' name='queryStr' value="{{queryStr}}" bindfocus='toggleSearch' bindconfirm='doQuery' bindinput="syncQuery"/>
     <view class='nav-search__delete' wx:if='{{!isSearch}}' bindtap='deleteAll'></view>
     <view class='nav-search__btn center' wx:if='{{!isSearch}}' bindtap='doQuery'>搜索</view>
   </view>

   <view class='nav-filter' bindtap='toggleFilter'></view>
 </view>
 </template>

 <!--在其他文件中使用模板-->
 <import src="/template/template.wxml" />
 <template is='navsearch' data="{{...couponData}}"></template>

模塊化

對于公共的js可以寫在一個專門的js文件中,然后使用module.exports暴露接口。
通用的js文件使用require引入。

 var common = require('../../common/common.js');
 ...
 common.f(); //調(diào)用

redirectTo & navigateTo

redirectTo是重定向至某頁面,navigateTo是打開新的頁面,值得說明的一點是,使用navigateTo打開的頁面太多會導(dǎo)致小程序卡頓。

分享

 Page({
   onShareAppMessage: function () {
     return {
       title: 'your title!',
       path: '/xxxx/xxxx/xxxx',  //分享之后回到這個頁面
       success: function(res) {
         f(); //成功回調(diào);
       },
       fail: function(res) {
         f(); //失敗回調(diào);

       }
     }
   }
 })

提高列表滑動的流暢性

簡而言之就是頁面滾動到哪里,列表中的圖片就顯示到哪里,實現(xiàn)方法如下。

//js文件
 Page({
   loadImg:function(e) {
     //計算接下來加載哪幾張
     var index = Math.floor((e.detail.scrollTop - 8)/259.5);
     var temp = this.data.couponData.list; //完整的列表
     var min = Math.max(index * 2,0),max = Math.min(index * 2 + 8,temp.length);
     for(var i = min; i < max; i ++) {
       if(temp[i] && !temp[i].isImgRendered) {
         temp[i].isImgRendered = true; //列表中的每一項有一個標(biāo)記是否加載圖片的的屬性,默認(rèn)false,隨著頁面滾動,一個個變成true。
       }
     }
     this.setData({"couponData.list":temp});
     temp = null;
   },
 })

 //wxml文件中在scroll-view上綁定事件。
 <scroll-view class="section" scroll-y="true" bindscroll='loadImg'></scroll-view>

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論