注:这里代理的名字千万不能写/api,不然 https://api.weixin.qq.com里面的api会被替换掉
"/wxApi" : {
"target" : "https://api.weixin.qq.com",
"changeOrigin" : true, //是否跨域
"secure" : true, // 设置支持https协议的代理
"pathRewrite" : {
"^/wxApi" : ""
}
},
使用的时候
const mode = process.env.NODE_ENV === 'development' ? '/wxApi' : "https://api.weixin.qq.com"
const token = () => {
uni.request({
url: mode + '/cgi-bin/stable_token',
method: 'POST',
data: {
"grant_type": "client_credential",
"appid": "",
"secret": ""
},
success(res) {
uni.setStorageSync('access_token', res.data.access_token)
}
})
}