1,新建一个common.js
//const baseUrl =`http://192.192.192.183:9798`
import basesevers from './basesevers.js'
const baseUrl = basesevers.request1
const getEnumeration = (url = '', date = {}, type = '', header = {}, responseType = '') => {
return new Promise((resolve, reject) => {
uni.request({
method: "get",
url: baseUrl + url,
data: date,
responseType: responseType,
header: header,
}).then((response) => {
let [error, res] = response;
let tempOptions = [];
if (res.data.length > 0) {
tempOptions = [] = res.data
}
resolve(tempOptions);
}).catch(error => {
let [err, res] = error;
reject(err)
})
});
}
export default getEnumeration
2,在main.js里引用
import getEnumeration from './common/common.js'
Vue.prototype.$getEnumeration = getEnumeration;
3,页面里使用
async onLoad(options) {
var aa = await this.$getEnumeration(
this.$basesevers.baseService.getenumlist, {
TypeCode: 101
},
);
console.log(aa)
},
网友评论