function accountsIdentity(params, method) {
return new Promise((resolve) => {
wx.request({
url: `https://baidu.com/xxx/xxx`,
data: params,
method: method,
success: (data) => {
resolve(data.data)
}
})
})
}
module.exports = {
accountsIdentity
}
const axios = require('../../utils/axios.js') // 引用外部的js文件
const params = { type: 4, tenantId: 1164523599620829185 }
axios.accountsIdentity(params, 'get').then(res => {
console.log(res)
})
本文介绍了一种使用Promise封装微信小程序请求的方法,通过定义accountsIdentity函数实现对Baidu API的GET请求。文章展示了如何创建Promise实例,设置请求参数,以及如何处理成功响应。
1471

被折叠的 条评论
为什么被折叠?



