proxy解决跨域问题

在使用vite工具创建的项目中解决跨域问题:

在vue.config.js中配置如下代码:

const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({

transpileDependencies: true,

server:{

proxy:{

'/path':{

target:'https://i.maoyan.com',

changeOrigin:true,

rewrite:path=>path.replace('/^/path/','')

}

}

}

在使用vue-cli创建的项目中解决跨域问题:

需要在vue.config.js中配置如下代码:

复制代码
devServer:{
proxy:{
  '/path':{
    target:'https://i.maoyan.com',
    changeOrigin:true,
    // rewrite:path=>path.replace('/^\/path/','')
    pathRewrite:{
      '^/path':''
    }
  }
}

}

相关推荐
老华带你飞1 天前
建筑材料管理|基于springboot 建筑材料管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·学习·spring
一招定胜负1 天前
网络爬虫(第三部)
前端·javascript·爬虫
Shaneyxs1 天前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(13)
前端
半山烟雨半山青1 天前
微信内容emoji表情包编辑器 + vue3 + ts + WrchatEmogi Editor
前端·javascript·vue.js
码途潇潇1 天前
Vue 事件机制全面解析:原生事件、自定义事件与 DOM 冒泡完全讲透
前端·javascript
zmirror1 天前
Monorepo 在 Docker 中的构建方案方案
前端
用户47949283569151 天前
node_modules 太胖?用 Node.js 原生功能给依赖做一次大扫除
前端·后端·node.js
_Kayo_1 天前
TypeScript 学习笔记2
前端·javascript·typescript
海纳百川本尊760641 天前
Flutter框架核心原理深度解析
前端
Shaneyxs1 天前
从 0 到 1 实现CloudBase云开发 + 低代码全栈开发活动管理小程序(12)
前端