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':''}}
}
}