0.0.4 • Published 3 years ago
bx-wx-request v0.0.4
网络请求
安装
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)
}
}