前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >webpack之proxyTable设置跨域

webpack之proxyTable设置跨域

作者头像
lyudev
发布2022-08-04 10:54:21
1.1K0
发布2022-08-04 10:54:21
举报
文章被收录于专栏:代码即数据代码即数据

在平时项目的开发环境中,经常会遇到跨域的问题,尤其是使用vue-cli这种脚手架工具开发时,由于项目本身启动本地服务是需要占用一个端口的,所以必然会产生跨域的问题。在使用webpack做构建工具的项目中使用proxyTable代理实现跨域是一种比较方便的选择。 还是拿之前使用过的vue-cli举例。我们首先要在项目目录中找到根目录下config文件夹下的index.js文件。由于我们是在开发环境下使用,自然而然是要配置在dev里面:

代码语言:javascript
复制
 dev: {
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
          '/api': {
            target: 'http://116.62.128.194:8810/',
            changeOrigin: true,
            pathRewrite: {
              '^/api': ''
            }
          }
        },
    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
    /**
     * Source Maps
     */
    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,
    cssSourceMap: true
  },
代码语言:javascript
复制
axios.post(sheq +"grid/findGridListByCommunityId", {
            communityId:this.AddressForm.sqvalue
          }).then(function(res) {
            if (res.data.result == 0) {
            _this.wgvalue = res.data.data
            } else {
              _this.$message.error(res.data.msg);
            }
          })
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-03-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 代码即数据 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档