creact-react-app创建项目跨域的处理
2017-11-02 15:41
651 查看
最近求职中发现很多公司都在用react
和vue
开发,而自己最近一直使用与深入研究的是angular2+
系列,出去找工作人家根本不用angular2+
,虽然自己对react
也深入研究过并使用过,只是好久没用,面试也能说出个八九分,上班也可以直接拿起键盘干活的,只是每个公司用的状态机不一样而已,但是还是遭到别人的怀疑,vue
我是没项目经验,只是因为外面都在用自己不得不研究,虽然不能说精通,但是做项目是随时的。互联网这个行业怎么来说,学习是自己的事情,最近花点时间重新搞下react
–>reactnative
,不是因为工作需要,仅仅是个人需要提高下
一、使用create-react-app
脚手架创建react
项目
相对于我之前手动配置webpack幸福多了
1、全局安装
npm install create-react-app -g
2、创建一个项目
create-react-app 项目名称
3、启动项目
npm run start
二、处理跨域的问题
1、本地使用node搭建一个简单的服务器
2、
react中直接安装并使用
axios请求数据的包
3、在
package.json配置跨域的服务器(直接在最后加上就好)
"proxy":"http://localhost:4000/" // 需要代理的服务器
4、在
react的钩子函数中
componentDidMount(){ axios.get('/xxx').then(res=>{ console.log(res); }) }
三、发布build
后使用nginx
处理跨域
1、运行打包命令npm run build
2、配置
nginx.conf不清楚的可以见
四、扩展
1、有人会用dva脚手架
2、参考
相关文章推荐
- creact-react-app创建react项目配置scss
- create-react-app创建react项目,使用axios跨域
- react-native create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理
- create-react-app如何创建react项目?
- 以create-react-app为基础创建项目
- ionic2项目创建回顾 及 react-native 报错处理
- react以create-react-app为基础创建项目
- 使用create-react-app或者antd创建一个React项目
- 以create-react-app为基础创建项目
- create-react-app创建项目报错SyntaxError: Unexpected end of JSON input while parsing near '...ttachment":false,"tar' npm代理
- react---学习笔记:使用create-react-app快速构建开发环境并创建项目
- 通过 npm 创建 React App 项目
- Create-React-App创建React项目
- 使用create-react-app创建项目
- 通过creact-react-native-app构建项目遇到的坑
- 在create-react-app创建的React项目应用中配置JQ、Sass
- 在create-react-app创建的项目下允许函数绑定运算符
- create-react-app 创建项目失败
- Create React App快速创建React项目
- 最新-使用create-react-app 生成项目怎么处理scss预处理器