码迷,mamicode.com
首页 > 其他好文 > 详细

react添加多个域名,跨域

时间:2019-07-11 19:59:59      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:post   show   version   tar   start   hang   targe   var   geo   

在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": {}一直,便可成功访问

 

 

react添加多个域名,跨域

标签:post   show   version   tar   start   hang   targe   var   geo   

原文地址:https://www.cnblogs.com/yinhao-jack/p/11171918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!