Vue 本地开发跨域

vue-cli3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:3000', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}

// ajax

// 请求 http://localhost:8080/api/XXXXXX
// 实际请求 http://localhost:3000/XXXXXX