yfCommon.js
//封装过的POST请求 function request(url,data,callback) { uni.showLoading({ title:'加载中' }) uni.request({ url: getApp().globalData.apiUrl + url, method: "POST", data: data, header: { "Content-Type": "application/json", "Authorization": getApp().globalData.userToken }, success: function(res) { uni.hideLoading(); callback(res.data); } }) } export default{ request }
main.js中添加代码
import yfCommon from './yfCommon.js' Vue.prototype.yfCommon=yfCommon;
调用代码
var that = this; this.yfCommon.request('/api/Activity/detail',{id:that.id},function(res){ //.... })