• react添加多个域名proxy代理,跨域


    在package.json中加入如下:

     1 {
     2   "name": "demo",
     3   "version": "0.1.0",
     4   "private": true,
     5   "proxy": {
     6     "/demo": {
     7       "secure": false,
     8       "target": "http://192.168.10.210:8080",
     9       "changeOrigin": true
    10     },
    11 
    12     "/TouTiao": {
    13       "secure": false,
    14       "target": "http://api.avatardata.cn",
    15       "changeOrigin": true
    16     },
    17     "/api": {
    18     "secure": false,
    19     "target": "http://dev.zxxk.com",
    20     "changeOrigin": true
    21     },
    22     "/ent": {
    23       "secure": false,
    24       "target": "https://interface.sina.cn",
    25       "changeOrigin": true
    26     },"/mobile": {
    27       "secure": false,
    28       "target": "http://mini.eastday.com",
    29       "changeOrigin": true
    30     }
    31   },
    32   "dependencies": {
    33     "antd": "^3.15.2",
    34     "axios": "^0.18.0",
    35     "http-proxy-middleware": "^0.19.1",
    36     "jsonp": "^0.2.1",
    37     "react": "^16.8.5",
    38     "react-dom": "^16.8.5",
    39     "react-router-dom": "^5.0.0",
    40     "react-scripts": "1.1.1",
    41     "react-swipe": "^6.0.4",
    42     "swipe-js-iso": "^2.1.5"
    43   },
    44   "scripts": {
    45     "start": "react-scripts start",
    46     "build": "react-scripts build",
    47     "test": "react-scripts test",
    48     "eject": "react-scripts eject"
    49   },
    50   "eslintConfig": {
    51     "extends": "react-app"
    52   },
    53   "browserslist": [
    54     ">0.2%",
    55     "not dead",
    56     "not ie <= 11",
    57     "not op_mini all"
    58   ]
    59 }

    然后接口部分:
     1     getRuleAction(){
     2         var self = this;
     3         return axios.post('/ent/feed.d.json?ch=health&col=ent&act=more&t=1484477669001&show_num=10&page=4').then((res) => {
     4             console.log("res",res.data.data)
     5             if (res.data.status == '1') {
     6                 let datalist=[]
     7                     this.setState({dataList:res.data.data});
     8             }
     9         }).catch(function (error) {
    10             console.log(error);
    11         })
    12 
    13 
    14     }


    接口处的、ent要和package.json中的 "/ent": {}一直,便可成功访问
  • 相关阅读:
    Future和Callable的使用
    Tiny Jpeg Decoder (JPEG解码程序) 源代码分析 1:解码文件头
    jQuery 表格排序插件 Tablesorter 使用
    jQuery 表单验证插件 jQuery Validation Engine 使用
    jQuery 文本编辑器插件 HtmlBox 使用
    开源视频质量评价工具: IQA
    hql 语法与详细解释
    MYSQL常用命令
    C++发送HTTP请求获取网页HTML代码
    编译运行Red5源代码
  • 原文地址:https://www.cnblogs.com/yinhao-jack/p/11171918.html
Copyright © 2020-2023  润新知