VUE代理Axios配置配置

在根目录新建vue配置vue.config.js

// vue-cli 配置项
module.exports = {
    publicPath:'/',
    devServer: {
        port: 8081,
        proxy: {
            '/api':{
                target:'http://127.0.0.1:5000',
                changeOrigin:true,
                ws:true,
                pathRewrite:{
                    '^/api':''
                }
            }
        }
    }
};

路由代码

export default {
    name:"test",
    data(){
        return {info:""}
    },
    mounted () {
       // console.log("hello")
    this.axios
      .get('/api/say?data=123')
      .then(response => (this.info = response.data))
      .catch(function () { // 请求失败处理
        console.log("error");
      });
  }
}
发布了177 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_38331049/article/details/104574080