天天看点

2021-02-15

//封装一个myRequest方法,在交互的时候方便拿来调用

//https://api-hmugo-web.itheima.net/api/public/v1可以替换成自己公用的接口地址

const BASE_URL = ‘https://api-hmugo-web.itheima.net/api/public/v1’

export const myRequest = (options) => {

return new Promise((resolve,reject) => {

uni.request({

url: BASE_URL + options.url,

method: options.method || ‘GET’,

data: options.data || {},

success: (res) => {

if (res.data.meta.status!==200) {

return uni.showToast({

title:‘获取数据失败’

})

}

resolve(res)

},

fail: (err) => {

uni.showToast({

title: ‘获取接口失败’

})

reject(err)

}

})

})

}

继续阅读