1.在vue.config.js中加入代理配置
- devServer: {
- port: 8082,
- open: true,
- overlay: {
- warnings: false,
- errors: true
- },
- proxy: {
- '/api': {
- target: 'http://localhost:8081', // 目标代理接口地址
- changeOrigin: true, // 开启代理,在本地创建一个虚拟服务端
- // ws: true, // 是否启用websockets
- pathRewrite: {
- '^/api': ''
- }
- }
- }
- }
2.使用axios调用用"/api”代替
- axios({
-
- url: "/api/xx/list"
-
- }).then(result => {
-
- console.log(result);
-
- })
3.hosts 配置相应域名
127.0.0.1 localhost