当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Vue开发环境跨域访问问题

Vue开发环境跨域访问问题

2020年03月09日  | 移动技术网IT编程  | 我要评论

vue开发环境跨域访问其他服务器或者本机其他端口,需要配置项目中config/index.js文件,修改如下

module.exports = {
 dev: {

  // paths
  assetssubdirectory: 'static',
  assetspublicpath: '/',
  proxytable: {
   '/api':{
    target:'http://192.168.1.99:8080/',
    changeorigin:true,
    pathrewrite:{
     '^/api':''
    }
   }
  },

其中主要是加入

 proxytable: {
   '/api':{
    target:'http://192.168.1.99:8080/',
    changeorigin:true,
    pathrewrite:{
     '^/api':''
    }
   }
  }

这样你通过axios 或fetche访问  /api/** 便相当于跨域访问了

总结

以上所述是小编给大家介绍的vue开发环境跨域访问问题,希望对大家有所帮助!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网