vue 实现cli3.0中使用proxy进行代理转发

解决方法: 在vue项目的根目录下添加 vue.config.js文件,文件中需要按照下面写法来写 module.exports = { lintOnSave: true, devServer: { proxy: { // proxy all requests starting...

解决方法:

在vue项目的根目录下添加 vue.config.js文件,文件中需要按照下面写法来写

module.exports = {
 lintOnSave: true,
 
 devServer: {
 proxy: {
  // proxy all requests starting with /api to jsonplaceholder
  '/api': {
  target: 'http://localhost:8080', //代理接口
  changeOrigin: true,
  pathRewrite: {
   '^/api': '/mock' //代理的路径
  }
  }
 }
 }
}

然后你就可以在代码中使用 /api 来代替http://localhost:8080/mock啦

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
粪斗
粪斗

185 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章