摘要:本文将带你了解微信小程序开发之调用后台接口+热点新闻滚动展示,希望本文对大家学微信有所帮助。
本文将带你了解微信小程序开发之调用后台接口+热点新闻滚动展示,希望本文对大家学微信有所帮助。
1、微信JS文件,发送请求调用: //将返回接口数据,写入Page({data})里面//获取热点新闻,这个也是写在onload:function(){//code)里面的 wx.request({ url: 'https://m.xxiangfang.com/index.php/Home/Xiaoxxf/activity?is_hot=1',//热点新闻 data: {}, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT header: { 'Content-Type': 'application/json' }, success: function (res) { console.log(res.data) that.setData({ notices: res.data //一维数组,只取两条数据 }) }, fail: function () { // fail }, complete: function () { // complete } })2、后台php处理:使用curl调用即可,记得传参和token(key)标识3、JS文件里面【热点新闻滚动展示】:onLoad: function (res) { startNotice: function() { var me = this; var notices = me.data.notices || []; //console.log(this.data.notices) //就是这里有问题,数据还没从接口返回就跑到这里了 xzz-6.2 if( notices.length == 0 ) { //return; //是这里的问题,数据没加载过来,导致程序return; } var animation = me.animation; //animation.translateY( -12 ).opacity( 0 ).step(); // animation.translateY( 0 ).opacity( 1 ).step( { duration: 0 }); // me.setData( { animationNotice: animation.export() }); var noticeIdx = me.data.noticeIdx + 1; console.log(notices.length); if( noticeIdx == notices.length ) { noticeIdx = 0; } // 更换数据 setTimeout( function() { me.setData( { noticeIdx: noticeIdx }); }, 400 ); // 启动下一次动画 setTimeout( function() { me.startNotice(); }, 5000 );},onShow: function() { this.startNotice();},4、wxml的前段代码:<span style="color:#999999">热门活动</span><span style="color:#3273c3">{{notices[noticeIdx]}}</span>作者:PHP急先锋原文://www.cnblogs.com/xuzhengzong/p/6943307.html
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号