目录

微信小程序数据的接收详解

微信小程序数据的接收详解

小程序数据接收的详细流程


1.wxml:

日期{ {item.customer_date}}

customer_date  为我们需要接收的数据的字段名

wx:for="{ {date}}" 中的date 是我给需要接收的数据取的数组名字,接收的数据可以为多个

2.wxss:

.inputbox{

background: #FFFFFF;

height:65rpx;

font-size:35rpx;

line-height:65rpx;

}

3.js

var endDate=" “; //这里设置endDate为空,

Page({

data:{},

/**

  • 生命周期函数–监听页面加载

*/

onLoad: function (options) {

this.getdata();   //调用getdata 函数

},

getdata: function () {    //定义getdata 函数

var that = this;   // 这个地方非常重要,重置data{}里数据时候setData方法的this应为以及函数的this, 如果在下方的sucess直接写this就变成了wx.request()的this了

wx.request({

url: ‘http://localhost/api/booking/getdata’,//请求地址 这个根据实际情况写

data: {  //发送给后台的数据

},

header: {//请求头

“Content-Type”: “application/x-www-form-urlencoded”

},

method: “GET”,

success: function (res) {    // 请求成功

console.log(res.data);//res.data相当于ajax里面的data,为后台返回的数据

that.setData({//如果在sucess直接写this就变成了wx.request()的this了.必须为getdata函数的this,不然无法重置调用函数

date: res.data.data  //

})

},

fail: function (err) { console.log(err.data); },//请求失败

complete: function () { }//请求完成后执行的函数

})

},

})