vue-cli3之配置文件-vue.config.js

运行项目自动运行浏览器

module.exports = {
  lintOnSave: false,

  devServer: {
    port: 8081,   //  端口号
    host: "localhost",  
    open: true    //  配置自动启动浏览器
  }
};

使用proxy跨域

最终接口地址: http://localhost:3000/test
vue.config.js文件中配置:

module.exports = {
  devServer: {
    proxy: {
      // 接口是 '/api' 开头的才用代理
      '/api': {
        target: 'http://xxxx/device/',  // 目标地址
        changeOrigin: true,             // 是否改变源地址
        ws: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  }
}

home.vue

this.$http.get("/api/test")
    .then(res => {
      console.log(res);
    })
    .catch(err => {
      console.log(err);
    });
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容