关于apicloud开发中对vue和ajax方法的封装
2018-02-25 16:11
886 查看
先上图
![](http://img.blog.csdn.net/20180225160605764)
![](http://img.blog.csdn.net/2018022516061939)
封装js//封装方法
function Ardo(id, mydata, pagesize){
var ardo = new Vue({
el: '#'+id,
data: {
msg: '',
status: 1,
p: pagesize,
mydata:mydata
}
});
return ardo;
}
//封装方法ajax
function ArdoAjax(url, req, calback) {
api.ajax({
url: url,
method: 'post',
timeout: 5,
data: {
values: req
}
}, function(ret, err) {
calback(ret, err);
});
}调用方法:【vue】var mydata = {
"id": 587,
"mobile": "18290073076",
"loadType": "1",
"daiKuanFee": "8000",
"daiKuanQiXian": "2",
"cityName": "北京",
"userName": "邓宇邵齐",
"age": "29",
"sex": "男",
"zhiYe": "4",
"workName": "私企或民企",
"workAge": "24个月以上",
"gongzi": "6000~9999元",
"sheBao": "无社保",
"gongJiJin": "无公积金",
"descInfo": "",
"state": "1",
"createTime": "2018-01-18 18:07:08.0",
"carType": "2",
"isHasHouse": "1",
"fuZhai": "无负债",
"xinYongRecord": "5"
};
var ardo = Ardo('content', mydata);调用方法:ajax
var req = {
token: token,
deviceid: api.deviceId,
id:id
}
ArdoAjax(loanUserInfoDetailUrl, req, calbackfun);
封装js//封装方法
function Ardo(id, mydata, pagesize){
var ardo = new Vue({
el: '#'+id,
data: {
msg: '',
status: 1,
p: pagesize,
mydata:mydata
}
});
return ardo;
}
//封装方法ajax
function ArdoAjax(url, req, calback) {
api.ajax({
url: url,
method: 'post',
timeout: 5,
data: {
values: req
}
}, function(ret, err) {
calback(ret, err);
});
}调用方法:【vue】var mydata = {
"id": 587,
"mobile": "18290073076",
"loadType": "1",
"daiKuanFee": "8000",
"daiKuanQiXian": "2",
"cityName": "北京",
"userName": "邓宇邵齐",
"age": "29",
"sex": "男",
"zhiYe": "4",
"workName": "私企或民企",
"workAge": "24个月以上",
"gongzi": "6000~9999元",
"sheBao": "无社保",
"gongJiJin": "无公积金",
"descInfo": "",
"state": "1",
"createTime": "2018-01-18 18:07:08.0",
"carType": "2",
"isHasHouse": "1",
"fuZhai": "无负债",
"xinYongRecord": "5"
};
var ardo = Ardo('content', mydata);调用方法:ajax
var req = {
token: token,
deviceid: api.deviceId,
id:id
}
ArdoAjax(loanUserInfoDetailUrl, req, calbackfun);
function calbackfun(ret, err){ if(ret.code===0){ var loan_info = ret.data; ardo.mydata.id = loan_info.id; ardo.mydata.mobile = loan_info.mobile; ardo.mydata.loadType = loan_info.loadType; ardo.mydata.daiKuanFee = loan_info.daiKuanFee; ardo.mydata.daiKuanQiXian = loan_info.daiKuanQiXian; ardo.mydata.cityName = loan_info.cityName; ardo.mydata.userName = loan_info.userName; ardo.mydata.age = loan_info.age; ardo.mydata.sex = loan_info.sex; ardo.mydata.zhiYe = loan_info.zhiYe; ardo.mydata.workName = loan_info.workName; ardo.mydata.workAge = loan_info.workAge; ardo.mydata.gongzi = loan_info.gongzi; ardo.mydata.sheBao = loan_info.sheBao; ardo.mydata.gongJiJin = loan_info.gongJiJin; ardo.mydata.descInfo = loan_info.descInfo; ardo.mydata.state = loan_info.state; ardo.mydata.createTime = loan_info.createTime; ardo.mydata.carType = loan_info.carType; ardo.mydata.isHasHouse = loan_info.isHasHouse; ardo.mydata.fuZhai = loan_info.fuZhai; ardo.mydata.xinYongRecord = loan_info.xinYongRecord; }else{ api.alert({ msg: JSON.stringify(ret.message) }); } }
相关文章推荐
- vue-cli开发时,关于ajax跨域的解决方法(推荐)
- 自己动手开发Vue插件(之一)Vue插件之公共方法封装
- 关于前后端分离开发的方法,jQuery的Mockjax:Ajax请求模拟
- 关于Ajax寄己封装方法 和 使用jqurey方法对比
- 关于ajax的url,data,success,error封装方法。(易与后期修改维护)
- vue+axios方法封装(restful,ajax)
- vue 组件的封装之基于axios的ajax请求方法
- 关于Ajax 错误:'sys'未定义解决方法.
- AJAX 开发的两种不同的方法[转]
- 关于Ajax 错误:'sys'未定义解决方法
- 网友关于单元测试的感悟(来自javaeye)--对敏捷软件开发方法的一些体会
- AJAX中关于多个UpdatePanel 的 UpdateProgress 的使用方法
- 关于Ajax 错误:'sys'未定义解决方法.
- 关于Delphi中DLL封装对象的几种方法整理及体会
- 关于Ajax 错误:'sys'未定义解决方法.
- 关于开发在线网页编辑器按回车会输入<p>而不是<br>的解决方法
- 关于ASP.NETAJAX控件开发中引用其自带控件的脚本
- Ajax: A New Approach to Web Applications(Ajax: 开发web应用的新方法)
- 下一代的软件开发方法:关于面向工作流的图形化企业管理软件开发
- 关于Ajax 错误:'sys'未定义解决方法