配置Vue前端跨域

  • 首先安装axios
npm install axios
  • 其次在config下的index.js中修改proxyTable
     
    proxyTable: {
      '/api': {
        target:'http://127.0.0.1:8000', 
        // secure: false, // 如果是https接口,需要配置这个参数
        changeOrigin:true,
        pathRewrite:{
          '^/api': ''
        }
      }
    },
  • 最后在main.js中将其注册(注意除了修改src中的文件外,都需要重启npm)
import axios from 'axios'


Vue.prototype.axios = axios
posted @ 2020-01-02 00:17  手可摘星辰/*  阅读(5432)  评论(0编辑  收藏  举报