小程序企业模块作业总结

原创2018-12-18 16:12:27109
摘要:作业总结:做下来基本没什么问题,就差熟练运用我发现以下问题。"content-type":"application/json"//用这个header只能用get来请求,"Content-Type": "application/x-www-form-urlencoded"//用这个header才能用post来请

作业总结:做下来基本没什么问题,就差熟练运用

  1. 我发现以下问题。"content-type":"application/json"//用这个header只能用get来请求,

  2. "Content-Type": "application/x-www-form-urlencoded"//用这个header才能用post来请求,

// utils/util.js
var requestUrl ="http://www.co.com/index.php/";
function post(url,data,fun,that,method){
console.log(url);
console.log("正式获取");
var postUrl=requestUrl+url;
console.log(postUrl);
wx.request({
url: postUrl,
data:data,
method:method,
dataType:"json",
header:{
"content-type":"application/json"//用这个header只能用get来请求,
// "Content-Type": "application/x-www-form-urlencoded"//用这个header才能用post来请求,
},
success:function(res){
console.log('请求成功');
that[fun](res.data.result);
},
fail:function(res){
console.log('请求失败,请重试');
return{};
}
})
}
module.exports.post=post

以下是作业。

作业代码:

// pages/shop/list.js
var com = require("../../utils/util.js");
var page=1;
var total_page=0;
Page({

/**
   * 页面的初始数据
   */
data: {
min_height: [],
index_list:[]
},

/**
   * 生命周期函数--监听页面加载
   */
onLoad: function (options) {
var sync = wx.getSystemInfoSync();
this.setData({
min_height:sync.windowHeight
})
com.post('Api/Home/shop_list', {page:page}, "setContent", this, "GET");
},
setContent: function (e) {
console.log(e);
total_page=e.total;
this.setData({
index_list: this.data.index_list.concat(e.lists),
});
},
onList:function(){
page=page+1;
console.log('1111');
if (total_page>=page){
com.post('Api/Home/shop_list', { page: page }, "setContent", this, "GET");
}
}
})
// pages/news/details.js
var com = require("../../utils/util.js");
Page({

/**
   * 页面的初始数据
   */
data: {
shopdetail: []
},

/**
   * 生命周期函数--监听页面加载
   */
onLoad: function (options) {
com.post('Api/Home/shop_details', { id: options.id }, "setContent", this,"get");
},
setContent: function (e) {
console.log(e);
this.setData({
shopdetail: e,
});
}
})


批改老师:查无此人批改时间:2018-12-18 16:29:40
老师总结:完成的不错,还有大发现,可以分享给大家,你也当当老师。

发布手记

热门词条