微信小程序 異步請求拿數據+使用外部js庫


  • 信小程序(與js)通過requirejs引用外部js文件

var modelSearch = require('../../utils/modelSearch.js') 這是一個構建數據請求篩選條件的庫文件

需要在modelSearch中暴露出函數 使用導出函數對象將函數導出到接收對象

module.exports.GetWhereAndOrderBy = GetWhereAndOrderBy;

module.exports.whereOptionAll = whereOptionAll;

module.exports.SearchAjaxPage = SearchAjaxPage;
module.exports.GetOption=GetOption;
module.exports.NoNull=NoNull;

使用module.exports導出函數

 

  • 使用api接口請求異步數據  

 

使用微信提供的api函數 使用方法與jq的Ajax函數類似

var urlHead='http://120.236.148.71:108/';
function SearchAjaxPage(getType, whereStr,callFn) {
 
   wx.request({
  url: urlHead+ '/PublicData/' + getType + '?where=' + whereStr, //僅為示例,並非真實的接口地址
  data: {
   
  },
  header: {
      'content-type': 'application/json'
  },
  success: function(res) {
    callFn(res);
  }
})

  


}

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM