uniapp下uni.request请求的封装


//核心代码,需要使用vue.use全局注册,只需参照博主的封装axios

// import {apiServer} from './../../common.js'
class http {
    static request(url, params = {}, method = "POST", contentType = "application/x-www-form-urlencoded") {
        return new Promise((resolve, reject) => {
            uni.request({
                url, //仅为示例,并非真实接口地址。
                data: params,
                header: {
                    'Content-Type': contentType
                },
                method,
                success: (res) => {
                    resolve(res.data.data);
                }
            });
        })
    }
}
export default http


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM