微信小程序-2.4 调用接口并展示(快递查询)
2018-01-16
- 调用接口并展示
- 了解微信小程序API,了解wx.request请求方式
wx.request({ url: 'test.php', //仅为示例,并非真实的接口地址 data: { x: '' , y: '' }, header: { 'content-type': 'application/json' // 默认值 }, success: function(res) { console.log(res.data) } })
//将代码块放入 app.js 中并声明一个方法,需要配置参数组、回调方法
queryaction : function (id,callback){}
//在调用页面中加入
const app = getApp();
//在事件中加入
app.queryaction(param,callback){}
- 反复注意如果 wx:for="{{list}}" 在这view中遍历需要写出 {{item}},类似 $.each(list,function(model,index){})
- 在view中只写wx:for="{{list}}" 会报错,这个错误并不影响开发,加上wx:key = "list的主键参数” 便不会报错了 报错内容如下
Now you can provide attr "wx:key" for a "wx:for" to improve performance.
- 将制定模块在局部区域具有滚动效果可以在制定模块的外层加入 scroll-view 组件