nuxt.js 本地开发跨域问题(Access-Control-Allow-Origin)及其解决方案

先运行npm i @gauseen/nuxt-proxy -D  

再nuxt.config.js的module.exports 里面添加如下代码

  modules:[
    '@nuxtjs/axios',
    // 请求代理配置,解决跨域
    '@gauseen/nuxt-proxy',
  ],

  // 代理服务器
  proxyTable: {
    "/apis": {
      target: "http://xxx.con",  // 线上地址
      // target: "http://192.168.1.106:7000",  // 本地环境
      pathRewrite: {"^/apis" : ""}
    }
  },

  

猜你喜欢

转载自www.cnblogs.com/hpx2020/p/9820990.html