网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序調用后臺接口+熱點新聞滾動展示

發布時間:2018-04-20 10:44 所屬欄目:小程序開發教程

1、微信JS文件,發送請求調用: //將返回接口數據,寫入Page({data})里面

 

				
  1. //獲取熱點新聞,這個也是寫在onload:function(){//code)里面的
  2. wx.request({
  3. url: 'https://m.xxiangfang.com/index.php/Home/Xiaoxxf/activity?is_hot=1',//熱點新聞
  4. data: {},
  5. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  6. header: {
  7. 'Content-Type': 'application/json'
  8. },
  9. success: function (res) {
  10. console.log(res.data)
  11. that.setData({
  12. notices: res.data //一維數組,只取兩條數據
  13. })
  14. },
  15. fail: function () {
  16. // fail
  17. },
  18. complete: function () {
  19. // complete
  20. }
  21. })

2、后臺php處理:

使用curl調用即可,記得傳參和token(key)標識

3、JS文件里面【熱點新聞滾動展示】:

 

				
  1. onLoad: function (res) {
  2. startNotice: function() {
  3. var me = this;
  4. var notices = me.data.notices || [];
  5. //console.log(this.data.notices) //就是這里有問題,數據還沒從接口返回就跑到這里了 xzz-6.2
  6. if( notices.length == 0 ) {
  7. //return; //是這里的問題,數據沒加載過來,導致程序return;
  8. }
  9.  
  10. var animation = me.animation;
  11. //animation.translateY( -12 ).opacity( 0 ).step();
  12. // animation.translateY( 0 ).opacity( 1 ).step( { duration: 0 });
  13. // me.setData( { animationNotice: animation.export() });
  14.  
  15. var noticeIdx = me.data.noticeIdx + 1;
  16. console.log(notices.length);
  17. if( noticeIdx == notices.length ) {
  18. noticeIdx = 0;
  19. }
  20.  
  21. // 更換數據
  22. setTimeout( function() {
  23. me.setData( {
  24. noticeIdx: noticeIdx
  25. });
  26. }, 400 );
  27.  
  28. // 啟動下一次動畫
  29. setTimeout( function() {
  30. me.startNotice();
  31. }, 5000 );
  32. },
  33.  
  34. onShow: function() {
  35. this.startNotice();
  36. },

4、wxml的前段代碼:

 

				
  1. <span style="color:#999999">熱門活動</span><span style="color:#3273c3">{{notices[noticeIdx]}}</span>


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23762.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×