当前位置:
首页 >
微信小程序--后台交互/wx.request({})方法/渲染页面方法 解析
发布时间:2025/7/14
56
豆豆
生活随笔
收集整理的这篇文章主要介绍了
微信小程序--后台交互/wx.request({})方法/渲染页面方法 解析
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
小程序的后台获取数据方式get/post具体函数格式如下:wx.request({})
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | data: { logs:[] }, onLoad:function(){ this.getdata(); } getdata:function(){//定义函数名称 var that=this; // 这个地方非常重要,重置data{}里数据时候setData方法的this应为以及函数的this, 如果在下方的sucess直接写this就变成了wx.request()的this了 wx.request({ url:'http://www.phonegap100.com/appapi.php?a=getPortalCate',//请求地址 data:{//发送给后台的数据 name:"bella", age:20 }, header:{//请求头 "Content-Type":"applciation/json" }, method:"GET",//get为默认方法/POST success:function(res){ console.log(res.data);//res.data相当于ajax里面的data,为后台返回的数据 that.setData({//如果在sucess直接写this就变成了wx.request()的this了.必须为getdata函数的this,不然无法重置调用函数 logs:res.data.result }) }, fail:function(err){},//请求失败 complete:function(){}//请求完成后执行的函数 }) }, wxml页面: <view wx:for="{{logs}}" wx:for-item="value"> {{value.catname}} </view> |
页面结果:
转载于:https://www.cnblogs.com/frx666/p/6591256.html
总结
以上是生活随笔为你收集整理的微信小程序--后台交互/wx.request({})方法/渲染页面方法 解析的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Markdown语法记录
- 下一篇: 设置cookie和查找cookie的方法