# uni-app接口封装 **Repository Path**: brown-bears/uni-app_requset ## Basic Information - **Project Name**: uni-app接口封装 - **Description**: 简单的uni-app接口封装方法 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-22 - **Last Updated**: 2022-11-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: 前端 ## README **1、request.js** ``` const myRequest = (options = {}) => { let baseUrl = 'http://www.xxx.com/';//请求接口地址前缀 return new Promise((resolve, reject) => { uni.request({ url: baseUrl + options.url, //请求接口地址 method: options.method || 'GET', //请求方式,默认get data: options.data || {}, // header: options.header || {}, //请求头 success: (res) => { resolve(res.data) }, fail: (err) => { reject(err) } }) }); } export default { myRequest } ``` **2、全局引用** ``` import myRequest from '@/requset/requset.js' Vue.prototype.$request = myRequest ``` **3、使用** ``` async mounted() { let a = await this.$request.myRequest({ url:'Test/test', method : 'post' }) console.log(a); } ```