axios cross-domain problem
Problem Description:
- After using vue+axios to develop a post request, the cross-domain problem in the following picture appears;
Solution:
I read some related information on the Internet and finally found a solution
module.exports = {
dev: {
//...
proxyTable: {
'/api': {
port: 3000,
target: 'http://127.0.0.1:8081/',
chunkOrigins: true,
pathRewrite: {
'^api': ''
}
}
}
}
- Modify proxyTable in the index.js file in the config directory
- chunkOrigins is whether to enable cross-domain
axios.request({
url: '/api/sysUser/selectUserInfo',
method: 'POST'
}).then(res => {
console.log(res);
}).catch(res => {
console.log('error' + res);
})
Modify axios in the vue component method
Restart the project and send the post request again, the program is normal