加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react添加多个域名,跨域

发布时间:2020-12-15 16:14:58 所属栏目:百科 来源:网络整理
导读:在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": true10 },11 12 "/TouTiao": {13 "secure": fa

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读