web.js
576 Bytes
import { MAP_OPTIONS } from '../helper/constants'
export default async (RequestMethods, method, obj = {}) => {
const params = []
Object.keys(obj).map(key => {
params.push(`${key}=${encodeURIComponent(obj[key])}`)
})
try {
const res = await window.fetch(`${MAP_OPTIONS.domain}${method}?${params.join('&')}`, {
method: RequestMethods
})
const data = await res.json()
if (data.status == '1') return data
else throw data.info
} catch (error) {
console.error(`接口异常:`, error)
throw error
}
}