直接上代码
request.js文件
export default {
common: {
baseUrl: "http://172.20.4.212:3000/api",
data: {},
header: {
"Content-Type": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
method: "GET",
dataType: "json"
},
request (options = {}) {
uni.showLoading({
title: '加载中...'
})
options.url = this.common.baseUrl + options.url
options.data = options.data || this.common.data
options.header = options.header || this.common.header
options.method = options.method || this.common.method
options.dataType = options.dataType || this.common.dataType