0


2024年前端最新vue配置proxy跨域代理_vue配置多个跨域proxy(2),2024年最新前端面试精讲

最后

文章到这里就结束了,如果觉得对你有帮助可以点个赞哦

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

const { defineConfig } = require(‘@vue/cli-service’)
module.exports = defineConfig({
devServer:{
proxy:{
// 代理1
// 当你请求是以/api开头的时候,则我帮你代理访问到http://127.0.0.1:3000
‘/api’: {
target: ‘http://127.0.0.1:3000’,
// secure: false,// 如果是https接口,需要配置这个参数
// ws: true, //是否代理websockets, 默认值为true

  1. /\*

changeOrigin设置为true时,服务器收到的请求头中的host为:localhost:3000
changeOrigin设置为false时,服务器收到的请求头中的host为:localhost:8080
changeOrigin默认值为true
*/

  1. changeOrigin: true, // 设置请求头中的host地址,默认值为true
  2. //地址中的 /api 仅仅是一个请求转发标志,真正的接口中没有/api,所以在转发时重写请求路径,把/api删掉。
  3. pathRewrite: {'^/api' : ''}
  4. },
  5. // 代理2
  6. '/douyu':{
  7. target: 'http://open.douyucdn.cn',
  8. pathRewrite: {'^/douyu' : ''}
  9. }
  10. }

}

  1. #### 设置多个代理

const { defineConfig } = require(‘@vue/cli-service’)
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false, //是否使用link检查代码
devServer: {
//方式二:设置多个代理
proxy:{
//这个路径为http://192.168.1.182:3000/douyu/wgapi/vod/front/vodrank/getTagVideos
‘/douyu’:{
//target是代理的目标路径
target:“http://192.168.1.182:3000”,
//pathRewrite重写请求的路径,实际请求的路径没有代理标识douyu,需要把斗鱼重置为空字符串
pathRewrite:{‘^/douyu’:‘’}
},
//这个路径为http://192.168.1.182:3000/huya/wgapi/vod/front/vodrank/getTagVideos
‘/huya’:{
//target是代理的目标路径
target:“http://192.168.1.182:3000”,
//pathRewrite重写请求的路径,实际请求的路径没有代理标识douyu,需要把斗鱼重置为空字符串
pathRewrite:{‘^/huya’:‘’}
}
}
}
});

  1. #### 发送ajax请求的方法使用
  1. getData() {
  2. //douyu代理
  3. axios.post('http://localhost:8080/douyu/wgapi/vod/front/vodrank/getTagVideos', { tagId: 0 }).then(res => {
  4. console.log('res.data:', res.data);
  5. });
  6. //huya代理
  7. axios.post('http://localhost:8080/huya/wgapi/vod/front/vodrank/getTagVideos', { tagId: 0 }).then(res => {
  8. console.log('res.data:', res.data);
  9. });
  10. },
  1. ### 最后
  2. 小编综合了阿里的面试题做了一份前端面试题PDF文档,里面有面试题的详细解析
  3. **[开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】](https://bbs.csdn.net/topics/618166371)**
  4. ![](https://img-blog.csdnimg.cn/img_convert/45f2869b91b538dd3bb3290ba13bc806.png)
  5. ![](https://img-blog.csdnimg.cn/20210419193354991.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0tlcGxlcl9JSQ==,size_16,color_FFFFFF,t_70)
  6. 虽只说了一个公司的面试,但我们可以知道大厂关注的东西并举一反三,通过一个知识点延伸到另一个知识点,这是我们要掌握的学习方法,小伙伴们在这篇有学到的请评论点赞转发告诉小编哦,谢谢大家的支持!
  7. ,t_70)
  8. 虽只说了一个公司的面试,但我们可以知道大厂关注的东西并举一反三,通过一个知识点延伸到另一个知识点,这是我们要掌握的学习方法,小伙伴们在这篇有学到的请评论点赞转发告诉小编哦,谢谢大家的支持!
标签: 前端 vue.js 面试

本文转载自: https://blog.csdn.net/fksdskjfzxklzk/article/details/138514605
版权归原作者 fksdskjfzxklzk 所有, 如有侵权,请联系我们删除。

“2024年前端最新vue配置proxy跨域代理_vue配置多个跨域proxy(2),2024年最新前端面试精讲”的评论:

还没有评论