1. 程式人生 > >關於apicloud開發中對vue和ajax方法的封裝

關於apicloud開發中對vue和ajax方法的封裝

先上圖



封裝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) });
      }
  }