1.打开config/index.js

2.在dev配置对象中找到proxyTable:{}

3.添加如下配置

 // 配置反向代理,解决跨域请求
    proxyTable: {
      '/api': {
        target: 'http://www.ajax.cn',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/api'
        }
      }
    },

4.重启开发服务器npm run dev

发送请求示例

// 导入axios
import axios from 'axios'
axios.defaults.baseURL='http://localhost:8080'
axios.get('/api/json.php').then(function(res){
          console.log(res);
});

 

相关文章:

  • 2021-08-23
  • 2021-06-29
  • 2023-01-10
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-10-28
相关资源
相似解决方案