# bx-wechat-request **Repository Path**: khdemos/bx-wechat-request ## Basic Information - **Project Name**: bx-wechat-request - **Description**: 微信小程序网络请求 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-08-04 - **Last Updated**: 2021-08-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 网络请求 ## 安装 ``` npm i bx-wx-request ``` ## 网络请求示例 * get请求 ``` requestData() { request.get({ url: 'http://localhost:3000/travel', data: { id: '1001' }, tag: '网络请求' }).then(data => { console.log('data', data) }).catch(e => { console.log('e', e) }) } ``` * get async/await 请求 ``` async requestData() { try { let result = await request.get({ url: 'http://localhost:3000/travel', tag: '网络请求' data: { id: '1001' } }) console.log('result', result) } catch(e) { console.log('e', e) } } ``` * post请求 ``` requestData() { request.post({ url: 'http://localhost:3000/travel', data: { id: '1001' }, tag: '网络请求' }).then(data => { console.log('data', data) }).catch(e => { console.log('e', e) }) } ``` * post async/await 请求 ``` async requestData () { try { let result = await request.post({ url: 'http://localhost:3000/travel', tag: '网络请求', data: { id: '1001' } }) console.log('result', result) } catch(e) { console.log('e', e) } } ``` * all请求 ``` request.all([ { url: 'http://localhost:3000/travel', tag: '网络请求1' data: { id: '1001' }, method: 'GET' }, { url: 'http://localhost:3000/travel', tag: '网络请求2' data: { id: '1002' }, method: 'POST' } ]).then(result => { const [result1, result2] = result console.log('result', result1, result2) }).catch(e => { console.log(e) }) ``` * async/await 请求 ``` async requestData () { try { let result = await request.all([ { url: 'http://localhost:3000/travel', tag: '网络请求1 data: { id: '1001' }, method: 'GET' }, { url: 'http://localhost:3000/travel', tag: '网络请求2' data: { id: '1002' }, method: 'POST' } ]) const [result1, result2] = result console.log('result', result1, result2) } catch(e) { console.log('e', e) } } ``` * race请求 ``` request.race([ { url: 'http://localhost:3000/travel', tag: '网络请求1' data: { id: '1001' }, method: 'GET' }, { url: 'http://localhost:3000/travel', tag: '网络请求2' data: { id: '1002' }, method: 'POST' } ]).then(result => { const [result1, result2] = result console.log('result', result1, result2) }).catch(e => { console.log(e) }) ``` * async/await 请求 ``` async requestData () { try { let result = await request.race([ { url: 'http://localhost:3000/travel', tag: '网络请求1 data: { id: '1001' }, method: 'GET' }, { url: 'http://localhost:3000/travel', tag: '网络请求2' data: { id: '1002' }, method: 'POST' } ]) const [result1, result2] = result console.log('result', result1, result2) } catch(e) { console.log('e', e) } } ```