uniapp请求的封装

uinapp 发送请求的简单封装

api.js

const baseUrl = "https://hrapi.hrchain.tech"
// const baseUrl = ""

export let myRequest = (options) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + options.url,
            method: options.method || "GET",
            data: options.data || {}
        }).then(res => {
            resolve(res[1].data)
        }).catch(err => {
            reject(err)
        })
    })
}

main.js

import {myRequest} from './api/api.js'
Vue.prototype.$http=myRequest

你可能感兴趣的:(uniapp请求的封装)