False demonstration

Proxy: {// configure cross-domain '/ API ': {target: 'https://xx.xx.com:18083', changOrigin: true, pathRewrite: {'^/ API ': '' } }, '/user': { target: 'https://xx.xx.com/as', changOrigin: true, pathRewrite: { '^/user': '' } }, '/qq': { target: 'https://api.weixin.qq.com/', changeOrigin: true, pathRewrite: { '^/qq': '' } } }

When getting an interface

// WeChat request get_token(url) {return axios({method: 'get', baseURL: process.env.node_env === = 'development'? '/qq' : 'https://api.weixin.qq.com/', url, timeout: 10000, headers: { // 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', }, }).then( (response) => { return checkStatus(response) } ).then( (res) => { return checkCode(res) } ) },
// Get Accesstoken and OpenID Accesstoken with public ID information and code: async function(url) { const res = await http.get_token(url) if (res.status === 200) { const { access_token, openid } = res.data const userUrl = `sns/userinfo? access_token=${access_token}&openid=${openid}&lang=zh_CN` this.getUserInfo(userUrl) } },

Userinfo and /user in the configured cross-domain

const userUrl = `sns/userinfo? access_token=${access_token}&openid=${openid}&lang=zh_CN`

Solution:

  • to/userChange the name (if it contains it, it will match, if it doesn’t). Such as:/userurl
Proxy: {// configure cross-domain '/ API ': {target: 'https://xx.xx.com:18083', changOrigin: true, pathRewrite: {'^/ API ': '' } }, '/userurl': { target: 'https://xx.xx.com/as', changOrigin: true, pathRewrite: { '^/userurl': '' } }, '/qq': { target: 'https://api.weixin.qq.com/', changeOrigin: true, pathRewrite: { '^/qq': '' } } }