微信小程式封裝post,get
阿新 • • 發佈:2019-01-08
微信封裝post請求
// post請求 function postrequst(url,data) { return new Promise(function (resolve, reject) { wx.request({ url: 'https://cyclv.com/jiaju/index.php/Home/'+url, data: data, header: { "Content-Type": "application/x-www-form-urlencoded" }, method: "POST", success: function (res) { console.log(res) resolve(res) } }) }) }
呼叫的時候需要使用Promise使用如下方法
//引入檔案
const jichu = require('../../utils/jichu.js');
//調取
jichu.getLocation(openid).then(function (locationData) {
console.log(locationData);
})