目录

一、减小输入字符数
二、用props.children来引用位于前置标签和后置标签之间的内容

三、创建组件两条主要的途径

四、JSX属性采用驼峰式的大小写规则(即‘onClick’而非‘onclick’)

五、JSX只能渲染单一个根节点

六、JSX中不方便使用条件语句的解决方法

七、如何在JSX内部渲染HTML标签

八、列表子元素添加key可以提升virtual dom的子级校正(reconciliation)的速度

九、JSX内联样式采用驼峰式大小写规则,以保持和DOM属性一致

十、高阶组件的主要作用

十一、为什么要用immutable.js?

十二、window.fetch的浏览器兼容补丁 whatwg-fetch

十三、js ES6新函数的兼容浏览器垫片, babel-polyfill

十四、Redux-Thunk的作用是改造store.dispatch函数,让其可以接收函数进行分发,函数可带上(dispatch,getState)两参数进行传递

十五、如何编写redux自定义middleware中间件

十六、FSA(Flux Standard Action)结构的Action

十七、redux-saga的redux-saga/effects常用的指令

十八、redux使用过程中常用的lodash函数

十九、redux常用的驼峰化处理库humps

二十、redux常用的json格式化处理库normalizr

二十一、react中常用到的新的js函数

二十二、react中如何阻止事件冒泡

二十三、Create React App中的代码切割,Code Splitting in Create React App

二十四、React组件生命周期

二十五、setState注意事项

二十六、mobx在ReactJS项目中的运用

二十七、报Error: Plugin/Preset files are not allowed to export objects, only functions.错误的解决方案

一、减小输入字符数

代码如下:

  1. import React, { Component } from 'react';
  2.  
  3. class Hello extends Component {
  4. // ...
  5. }  

二、用props.children来引用位于前置标签和后置标签之间的内容

代码如下:

  1. import React, { Component } from 'react';
  2. import { render } from 'react-dom';
  3. // Parent Component
  4. class GroceryList extends Component {
  5. render() {
  6. return (
  7. <ul>
  8. <ListItem quantity = "1" > Bread </ListItem>
  9. <ListItem quantity = "6" > Eggs </ListItem>
  10. <ListItem quantity = "2" > Milk </ListItem>
  11. </ul>
  12. );
  13. }
  14. }
  15. // Child Component
  16. class ListItem extends Component {
  17. render() {
  18. return (<li> {this.props.quantity {this.props.children} </li>);
  19. }
  20. }
  21. render(<GroceryList /> , document.getElementById('root'));

三、创建组件两条主要的途径

从上而下或者从下而上,尽量让app.js保持简单,只包含数据(数据来自于API)并只渲染出一个KanbanBoard组件

  1. import React from 'react';
  2. import { render } from 'react-dom';
  3. import KanbanBoard from './KanbanBoard';
  4. let cardsList = [
  5. { id: 1, title: "Read the Book", description: "I should read the whole book", status: "in-progress", tasks: [] }, {
  6. id: 2,
  7. title: "Write some code",
  8. description: "Code along with the samples in the book",
  9. status: "todo",
  10. tasks: [
  11. { id: 1, name: "ContactList Example", done: true },
  12. { id: 2, name: "Kanban Example", done: false },
  13. { id: 3, name: "My own experiments", done: false }
  14. ]
  15. }
  16. ];
  17.  
  18. render( <KanbanBoard cards = { cardsList } />, document.getElementById('root'));

四、react属性采用驼峰式的大小写规则(即‘onClick’而非‘onclick’)

五、react只能渲染单一个根节点

代码如下:

  1. return (
  2. <h1>Hello World</h1>
  3. ) // 合法
  4.  
  5. return (
  6. <h1>Hello World</h1>
  7. <h2>Have a nice day</h2>
  8. ) // 不合法

六、JSX中不方便使用条件语句的解决方法

解决方案一、使用三元表达式

  1. render(){
  2. return (
  3. <div className={condition ? "show":"hide"}>
  4. Hello JSX
  5. </div>
  6. )
  7. }
  8. // 或者
  9. <div>
  10. {condition?
  11. <span> Hello JSX </span>
  12. : null}
  13. </div>

解决方案二、将条件外置

  1. render(){
  2. let className;
  3. if(condition) {
  4. className = "show";
  5. } else {
  6. className = "hide";
  7. }
  8. }
  9. return (
  10. <div className={className}>Hello JSX</div>
  11. )

七、如何在JSX内部渲染HTML标签

方式、1

  1. var HelloMessge = React.createClass({
  2. render: <div
  3. dangerouslySetInnerHTML={{
  4. __html: '<h3>hahhah</h3>'
  5. }}>
  6. </div>
  7. })

方式、2

  1. destroy() {
  2. if (this._el) {
  3. this._el.querySelector('.dialog__mask').classList.add('maskFadeOut')
  4. this._el.querySelector('.dialog__wrapper').classList.add('wrapperFadeOutUp')
  5. setTimeout(()=>{
  6. ReactDOM.unmountComponentAtNode(this._el)
  7. document.body.removeChild(this._el)
  8. this._el = null
  9. }, 150)
  10. }
  11. }
  12.  
  13. open() {
  14. this._el = document.createElement('div')
  15. document.body.appendChild(this._el)
  16. ReactDOM.unstable_renderSubtreeIntoContainer(
  17. this,
  18. this.renderDialog(),
  19. this._el
  20. ); // 更新组件到传入的 DOM 节点上,完成在组件内实现跨组件的 DOM 操作
  21. }
  22.  
  23. renderDialog() {
  24. const {
  25. skin,
  26. width,
  27. okBtn,
  28. okBtnText,
  29. children,
  30. cancelBtn,
  31. cancelBtnText
  32. } = this.props;
  33.  
  34. return (
  35. <div className="dialog" key="dialog">
  36. <div className="dialog__mask maskFadeIn dialog_animated" style={{height: (document.body.offsetHeight > window.screen.height ? document.body.offsetHeight : window.screen.height) + 'px'}} />
  37. <div className={'dialog__wrapper wrapperFadeInDown dialog_animated dialog__wrapper--skin-' + skin} style={{left:'50%', top: (window.screen.height/2 - 100) + 'px', width: width + 'px', marginLeft: (width*(-1)/2) + 'px'}} >
  38. <div className="dialog__content">
  39. {children}
  40. </div>
  41. {(okBtn || cancelBtn) && (
  42. <div className="dialog__btns">
  43. {okBtn && (<button className="dialog__btn dialog__btn--ok" onClick={this.onOk}>{okBtnText}</button>)}
  44. {cancelBtn && <button className="dialog__btn dialog__btn--cancel" onClick={this.onCancel}>{cancelBtnText}</button>}
  45. </div>
  46. )}
  47. </div>
  48. </div>
  49. )
  50.  
  51. }

  

八、列表子元素添加key可以提升virtual dom的子级校正(reconciliation)的速度

九、JSX内联样式采用驼峰式大小写规则,以保持和DOM属性一致  

十、高阶组件的主要作用

一:生成包含新功能的新组件

  1. function hoc(Comp){
  2. return class NewComponent extends Component {
  3. // 增加或者修改的功能实现
  4. extendFunc(){
  5. }
  6. render() {
  7. return (
  8. <Comp {... this.props} />
  9. )
  10. }
  11. }
  12.  
  13. }
  14.  
  15. const NewCompent = hoc(Comp);

二:控制props

  1. const MyContainer = (WrappedComponent) =>
  2. class extends Component {
  3. render() {
  4. const newProps = { text: newText };
  5. return <WrappedComponent {...this.props} {...newProps} />;
  6. }
  7. }

属性转换

  1. function transProps(transFn){
  2. return function(Comp){
  3. return class extends Component {
  4. render(){
  5. return <Comp {...transFn(this.props)} />
  6. }
  7. }
  8. }
  9. }

三:抽象state,高阶组件可以将原组件抽象为展示型组件,分离内部状态

  1. const MyContainer = (WrappedComponent) =>
  2. class extends Component {
  3. constructor(props){
  4. super(props);
  5. this.state = {
  6. name: '',
  7. };
  8. this.onNameChange = this.onNameChange.bind(this);
  9. }
  10. onNameChange( event ) {
  11. this.setState(
  12. name: event.target.value,
  13. )
  14. }
  15. render() {
  16. const newPros = {
  17. name: {
  18. value: this.state.name,
  19. onChange: this.onNameChange,
  20. }
  21. }
  22. return <WrappedComponent {...this.props} {...newProps} />;
  23. }
  24. }

四:封装异步请求

  1. function hocListWithData({dataLoader, getListFromResultData}) {
  2. return Com => {
  3. return class extends Component {
  4. constructor(props){
  5. super();
  6. this.state = {
  7. resultData: undefined
  8. }
  9. }
  10. componentDidMount(){
  11. dataLoader()
  12. .then(data=> this.setState({resultData: data})
  13. }
  14. render(){
  15. return {
  16. <Comp {...getListFromResultData(this.state.resultData)} {...this.props} />
  17. }
  18. }
  19. }
  20. }
  21. }

十一、为什么要用immutable.js?

举个例子,在javascript中

  1. var a = {a:1};
  2. var b = a;
  3. b.a = 2; // => a.a = 2

由上面的例子可以知道,可变数据有时使用起来是会有问题的,在各种数据操作后有可能会使原数据被污染而导致程序出错,才出现immutable.js不可修改数据类型的概念,因此,修改组件状态时,永远不能直接写:

  1. this.state.arr = newArr; // 或者
  2. const tempArr = this.state.arr;
  3. temp.push('hello'); // 此时已经修改了this.state了,不能这样写
  4. this.state.setState({newArr,tempArr })

可以使用非常侵入式的纯函数如:map、filter、concat或者Object.assign({}, this.state.xxx, {newKey, newValue})来解决这个问题

immutable例子如下:

  1. import React from 'react'
  2. import { Map, Set } from 'immutable';
  3.  
  4. export default class Clock extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. immutableData: Map({
  9. date: new Date(),
  10. name: 'Nelson won\'t change, but time is changing all the time!'
  11. })
  12. };
  13. this.dataSet = Set();
  14. }
  15.  
  16. componentDidMount() {
  17. this.timerID = setInterval(
  18. () => this.tick(),
  19. 10
  20. );
  21. let dataSet = Set();
  22. dataSet = dataSet.add(1);
  23. dataSet = dataSet.add(2);
  24. this.dataSet = dataSet;
  25. }
  26.  
  27. componentWillUnmount() {
  28. clearInterval(this.timerID);
  29. }
  30.  
  31. tick() {
  32. this.setImmutableState('date',new Date());
  33. }
  34.  
  35. setImmutableState(key, value) {
  36. this.setState({
  37. immutableData: this.state.immutableData.set(key, value)
  38. });
  39. }
  40.  
  41. render() {
  42. const formatTime = date => {
  43. let hour = date.getHours();
  44. let minute = date.getMinutes();
  45. let second = date.getSeconds();
  46. let milisecond = Math.floor(date.getMilliseconds() / 10);
  47. if (hour < 10) {
  48. hour = '0' + hour;
  49. }
  50. if (minute < 10) {
  51. minute = '0' + minute;
  52. }
  53. if (second < 10) {
  54. second = '0' + second;
  55. }
  56. if (milisecond < 10) {
  57. milisecond = '0' + milisecond;
  58. }
  59. return `${hour} : ${minute} : ${second} : ${milisecond}`;
  60. }
  61. return (
  62. <div>
  63. <h2>现在时间 {formatTime(this.state.immutableData.get('date'))}. Hello {this.state.immutableData.get('name')}. dataSetSize:{this.dataSet.size}</h2>
  64. </div>
  65. );
  66. }
  67. }

十二、window.fetch的浏览器兼容补丁 whatwg-fetch

  1. npm install --save whatwg-fetch
  1. import 'whatwg-fetch';

十三、js ES6新函数的兼容浏览器垫片, babel-polyfill

  1. npm install --save babel-polyfill

十四、Redux-Thunk的作用是改造store.dispatch函数,让其可以接收函数进行分发,函数可带上(dispatch,getState)两参数进行传递解决异步action传递的问题。

如下面action代码的写法,组件中可以直接写 dispatch(fetchPostsIfNeeded) 分发异步 action:

  1. export const requestPosts = reddit => ({
  2. type: REQUEST_POSTS,
  3. reddit
  4. })
  5.  
  6. export const receivePosts = (reddit, json) => ({
  7. type: RECEIVE_POSTS,
  8. reddit,
  9. posts: json.data.children.map(child => child.data),
  10. receivedAt: Date.now()
  11. })
  12.  
  13. const fetchPosts = reddit => dispatch => {
  14. dispatch(requestPosts(reddit))
  15. return fetch(`https://www.reddit.com/r/${reddit}.json`)
  16. .then(response => response.json())
  17. .then(json => dispatch(receivePosts(reddit, json)))
  18. }
  19.  
  20. const shouldFetchPosts = (state, reddit) => {
  21. const posts = state.postsByReddit[reddit]
  22. if (!posts) {
  23. return true
  24. }
  25. if (posts.isFetching) {
  26. return false
  27. }
  28. return posts.didInvalidate
  29. }
  30.  
  31. export const fetchPostsIfNeeded = reddit => (dispatch, getState) => {
  32. if (shouldFetchPosts(getState(), reddit)) {
  33. return dispatch(fetchPosts(reddit))
  34. }
  35. }

十五、如何编写redux自定义middleware中间件

自定义的middleware一般可以用做处理复杂的异步流,除了redux-thunk, redux-saga这些非常常用的中间件,我们可以自己定义一些中间件:

如处理轮询多异步串联、修改并重新封装action的值等,

一般的写法如下:

  1. // 如多异步串联
  2. const sequenceMiddleware = {dispatch, getState} => next => action => {
  3.   if(!Array.isArray(action)){
  4.     return next(action);
  5. }
  6.   return action.reduce((result, currAction) => {
  7.     return result.then() => {
  8.      return Array.isArray(currAction) ?
  9.       Promise.all(currAction.map(item => dispatch(item))) :
  10.         dispatch(currAction);
  11.     })
  12.   }, Promise.resolve());
  13. }
  14.  
  15. // 或者这样写
  16. export default store => next => action => {
  17.   // ...
  18. }

代码引用自:《深入react技术栈》  

十六、FSA(Flux Standard Action)结构的Action

  1. {
  2. type: 'ADD_TODO',
  3. payload: {
  4. text: 'Do something.'
  5. }
  6. }
  7. // 一个action必须是一个普通的JavaScript对象,有一个type字段
  8. // 一个action可能有error字段、payload字段、meta字段。
  9. // 一个action必须不能包含除type、payload、error及meta以外的其他字段。  

十七、redux-saga的redux-saga/effects常用的指令

  1. yield put({ type: 'INCREMENT' }) // put: 分发一个type为'INCREMENT'的action 到 Store
  2.  
  3. yield call(delay, 1000) // 不直接执行delay函数,用call便于跟踪及测试
  4.  
  5. yield call([obj, obj.method], arg1, arg2, ...) // 如同 obj.method(arg1, arg2 ...)
  6.  
  7. yield apply(obj, obj.method, [arg1, arg2, ...]) // callapply 非常适合返回 Promise 结果的函数
  8.  
  9. const content = yield cps(readFile, '/path/to/file') // cps 可以用来处理 Node 风格的函数 (例如,fn(...args, callback) 中的 callback 是 (error, result) => () 这样的形式,cps 表示的是延续传递风格(Continuation Passing Style))
  10.  
  11. yield* takeEvery('FETCH_REQUESTED', fetchData) // takeEvery 监听并允许多个 fetchData 实例同时启动
  12.  
  13. yield* takeLatest('FETCH_REQUESTED', fetchData) // takeLatest 监听并只允许执行一个 fetchData 任务。并且这个任务是最后被启动的那个。 如果之前已经有一个任务在执行,那之前的这个任务会自动被取消
  14.  
  15. // 错误处理
  16. function* fetchProducts() {
  17. try {
  18. const products = yield call(Api.fetch, '/products')
  19. yield put({ type: 'PRODUCTS_RECEIVED', products })
  20. }
  21. catch(error) {
  22. yield put({ type: 'PRODUCTS_REQUEST_FAILED', error })
  23. }
  24. }
  25.  
  26. // 简单的logger
  27. export function* watchAndLog() {
  28. while (true) {
  29. const action = yield take('*') // 监听所有action
  30. const state = yield select() // select作用和 redux thunk 中的 getState 相同
  31.  
  32. console.log('action', action)
  33. console.log('state after', state)
  34. }
  35. }
  36.  
  37. // select内容
  38. const id = yield select(state => state.id);
  39.  
  40. const tokenTask= yield fork(authorize, user, password) // 相比起call来说,fork是无阻塞调用
  41. yield cancel(tokenTask) // 可取消task
  42.  
  43. // 正确写法, effects 将会同步并行执行
  44. const [users, repos] = yield [
  45. call(fetch, '/users'),
  46. call(fetch, '/repos')
  47. ]
  48. // 当我们需要 yield 一个包含 effects 的数组, generator 会被阻塞直到所有的 effects 都执行完毕,或者当一个 effect 被拒绝 (就像 Promise.all 的行为)。
  49.  
  50. const {posts, timeout} = yield race({
  51. posts : call(fetchApi, '/posts'),
  52. timeout : call(delay, 1000)
  53. }) // race Effect 提供了一个方法,在多个 Effects 之间触发一个竞赛(race)。它会自动取消那些失败的 Effects
  54.  
  55. // yield* 对 Sagas 进行排序,可以使用内置的 yield* 操作符来组合多个 Sagas,使得它们保持顺序,如下:
  56. function* playLevelOne(getState) { /*...*/ }
  57. function* playLevelTwo(getState) { /*...*/ }
  58. function* playLevelThree(getState) { /*...*/ }
  59. function* game(getState) {
  60. const score1 = yield* playLevelOne(getState)
  61. put(showScore(score1))
  62.  
  63. const score2 = yield* playLevelTwo(getState)
  64. put(showScore(score2))
  65.  
  66. const score3 = yield* playLevelThree(getState)
  67. put(showScore(score3))
  68. }
  69.  
  70. // 任务的取消
  71. // 或直接使用 `isCancelError(error)`
  72. if(error instanceof SagaCancellationException)
  73. yield put(actions.requestFailure('Sync cancelled!'))

十八、redux使用过程中常用的lodash函数

  1. _.union([1, 2], [4, 2], [2, 1]); // 字符或者数字数组去重
  2. // => [1, 2, 4]
  3.  
  4. var users = {
  5. 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  6. };
  7.  
  8. var ages = {
  9. 'data': [{ 'age': 36 }, { 'age': 40 }]
  10. };
  11.  
  12. _.merge(users, ages); // 合并对象数组
  13. // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  14.  
  15. // using a customizer callback
  16. var object = {
  17. 'fruits': ['apple'],
  18. 'vegetables': ['beet']
  19. };
  20.  
  21. var other = {
  22. 'fruits': ['banana'],
  23. 'vegetables': ['carrot']
  24. };
  25.  
  26. _.merge(object, other, function(a, b) { // 按函数合并对象数组
  27. if (_.isArray(a)) {
  28. return a.concat(b);
  29. }
  30. });
  31. // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  32.  
  33. _.zip(['fred', 'barney'], [30, 40], [true, false]); // 数组按顺序组合成新数组
  34. // => [['fred', 30, true], ['barney', 40, false]]

十九、redux常用的驼峰化处理库humps

  1. humps.camelize('hello_world') // 'helloWorld'
  2. humps.decamelize('fooBar') // 'foo_bar'
  3. humps.decamelize('fooBarBaz', { separator: '-' }) // 'foo-bar-baz'
  4.  
  5. var object = { attr_one: 'foo', attr_two: 'bar' }
  6. humps.camelizeKeys(object); // { attrOne: 'foo', attrTwo: 'bar' }
  7.  
  8. var array = [{ attr_one: 'foo' }, { attr_one: 'bar' }]
  9. humps.camelizeKeys(array); // [{ attrOne: 'foo' }, { attrOne: 'bar' }]

二十、redux常用的json格式化处理库normalizr

  1. // 源数据
  2. {
  3. "id": "123",
  4. "author": {
  5. "id": "1",
  6. "name": "Paul"
  7. },
  8. "title": "My awesome blog post",
  9. "comments": [
  10. {
  11. "id": "324",
  12. "commenter": {
  13. "id": "2",
  14. "name": "Nicole"
  15. }
  16. }
  17. ]
  18. }
  19. // 处理
  20. import { normalize, schema } from 'normalizr';
  21.  
  22. // Define a users schema
  23. const user = new schema.Entity('users');
  24.  
  25. // Define your comments schema
  26. const comment = new schema.Entity('comments', {
  27. commenter: user
  28. });
  29.  
  30. // Define your article
  31. const article = new schema.Entity('articles', {
  32. author: user,
  33. comments: [ comment ]
  34. });
  35.  
  36. const normalizedData = normalize(originalData, article);
  37.  
  38. // =>
  39. {
  40. result: "123",
  41. entities: {
  42. "articles": {
  43. "123": {
  44. id: "123",
  45. author: "1",
  46. title: "My awesome blog post",
  47. comments: [ "324" ]
  48. }
  49. },
  50. "users": {
  51. "1": { "id": "1", "name": "Paul" },
  52. "2": { "id": "2", "name": "Nicole" }
  53. },
  54. "comments": {
  55. "324": { id: "324", "commenter": "2" }
  56. }
  57. }
  58. }

二十一、react中常用到的新的js函数

  1. const cart = json.carts.find(cart => cart.cartId === id);
  2. Object.assign({}, obj, obj);
  3. // reduce
  4. // map
  5. // filter ...还有 ... spread函数

二十二、react中如何阻止事件冒泡

  1. onDelete={(e) => {
  2. e.stopPropagation();
  3. e.nativeEvent.stopImmediatePropagation();
  4. onDelete(todo.id)
  5. }
  6. }

二十三、Create React App中的代码切割,Code Splitting in Create React App

参考:Code Splitting in Create React App

二十四、React组件生命周期

参考:React Component Lifecycle(生命周期)和 React组件生命周期小结

二十五、setState注意事项

1、setState是异步的。
2、setState会造成不必要的渲染,新的 state 其实和之前的有可能是一样的。这个问题通常可以通过 shouldComponentUpdate 来解决。也可以用 pure render 或者其他的库赖解决这个问题。
3、setState并不能很有效的管理所有的组件状态

二十六、mobx在ReactJS项目中的运用

引用自:http://blog.csdn.net/u012125579/article/details/69400169

mobx 最最核心的概念只有2个。 @observable 和 @observer ,它们分别对应的是被观察者观察者。这是大家常见的观察者模式,不过这里使用了,ES7 中的 装饰器。

核心概念2 actions 和 computed values,在 Component 中调用,这样通过 action 的方法,就避免了直接修改 props 的问题。可以通过引入 mobx 定义的严格模式,强制使用 action 来修改状态。mobx 提供了 computed 装饰器,用于获取由基础 state 衍生出来的值

  1. import React, {Component} from 'react';
  2. import { render } from 'react-dom';
  3. import {observable, action, computed,useStrict} from 'mobx';
  4. import {observer} from 'mobx-react';
  5.  
  6. useStrict(true);
  7.  
  8. class Store {
  9. @observable todos = [{ // 被观察者
  10. title: "todo标题",
  11. done: false,
  12. },{
  13. title: "已经完成 todo 的标题",
  14. done: true,
  15. }];
  16.  
  17. @action changeTodoTitle({index,title}){
  18. this.todos[index].title = title
  19. }
  20.  
  21. @computed get unfinishedTodos () {
  22. return this.todos.filter((todo) => todo.done)
  23. }
  24. }
  25.  
  26. @observer // 观察者
  27. class TodoBox extends Component {
  28.  
  29. render() {
  30. console.log('render');
  31. return (
  32. <div>
  33. <ul>
  34. { /* 把 unfinishedTodos 换成 todos,点击修改标题就会在控制台打印 "render".*/ }
  35. {this.props.store.unfinishedTodos.map(
  36. (todo,index) => <li key={index}>{todo.title}</li>
  37. )}
  38. </ul>
  39. <div>
  40. <input type="button" onClick={() => {
  41. this.props.store.changeTodoTitle({index:0,title:"修改后的todo标题"});
  42. }} value="修改标题"/>
  43. </div>
  44. </div>
  45. )
  46. }
  47. }
  48.  
  49. const store = new Store();
  50.  
  51. render(
  52. <TodoBox store={store} />,
  53. document.getElementById('root')
  54. );

二十七、报Error: Plugin/Preset files are not allowed to export objects, only functions.错误的解决方案

原因是 package.json 依赖包中既有 babel 7.0 版本,又有 babel 6.0 版本,就会报这个错误

解决方案:要么全部bebel相关的包升级到7.0,要么全部降级到6.0版的,再不行检查一下全部安装的babel版本,删除node_modules重新装包

react使用过程中常见问题的更多相关文章

  1. (转)CloudStack 安装及使用过程中常见问题汇总

    CloudStack 安装及使用过程中常见问题汇总             在做工程项目中对CloudStack 安装及使用过程中常见的几个问题及如何解决做一个总结.   1.Windows XP虚拟 ...

  2. Vue使用过程中常见问题

    目录 一.vue监听不到state数组/json对象内的元素的值的变化,要手动通知触发 二.vue用splice删除多维数组元素导致视图更新失败情况 三.vue项目如何部署到php或者java环境的服 ...

  3. Android Studio使用过程中常见问题及解决方案

    熟悉Android的童鞋应该对Android Studio都不陌生.Android编程有两个常用的开发环境,分别是Android Studio和Eclipse,之前使用比较多的是Eclipse,而现在 ...

  4. 【FAQ】接入HMS Core地图服务过程中常见问题总结

    HMS Core地图服务(Map Kit)给开发者提供一套地图开发调用的SDK,助力全球开发者实现个性化地图呈现与交互,方便轻松地在应用中集成地图相关的功能,全方位提升用户体验. 在日常工作中,我们会 ...

  5. 【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结

    华为运动健康服务(HUAWEI Health Kit)为三方生态应用提供了REST API接口,通过其接口可访问数据库,为用户提供运动健康类数据服务.在实际的集成过程中,开发者们可能会遇到各种问题,这 ...

  6. js/jQuery使用过程中常见问题

    目录 一.jQuery选择器选择选中的或者disabled的选择框时attr函数无效 二.jQuery each函数的break/continue 三.jQuery 获取元素的left会值/left数 ...

  7. js/jQuery使用过程中常见问题/已踩过的坑大杂烩

    目录 一.jQuery选择器选择选中的或者disabled的选择框时attr函数无效 二.jQuery each函数的break/continue 三.jQuery 获取元素的left会值/left数 ...

  8. Android无线测试之—Genymotion配置过程中常见问题

    一.前提条件: 已经部署好了Android UiAutomator测试环境. 二.在部署Genymotion时遇到了两类问题: 1.通过eclipse打开一个模拟设备,然后将编译好的jar包push到 ...

  9. Linux使用过程中常见问题及其解决方法

    “我不怕问题的出现,相反,我喜欢问题,因为我知道这是一种成长............” 1,ubuntu中文输入法的安装:  今天重装了英文版的ubuntu,而发现中文输入法并没有自动安装好,于是搜了 ...

随机推荐

  1. JSON使用与类型转换

    JSON语法与对象 JSON方法与使用 一.JSON语法与对象 JSON是英文JavaScript Object Notation(JavaScript 对象表示法)的缩写,是存储和交换文本信息的语法 ...

  2. Kubernetes基本功能

    说明 目前kubernetes的资料介绍很多也很深刻,本文只是做一个针对自己学习k8s过程的介绍,仅仅是学习笔记的记录. 一.基本使用 1. 命令行 集群信息 Namespace 信息 Control ...

  3. python3 练手实例3 摄氏温度与华氏温度转换

    def wd(): w=input('请输入一个摄氏温度或者一个华氏温度,如,34c/C or 34f/F:') if w[-1] in ['c','C']: w=float(w[:-1]) hs=1 ...

  4. 13、Ajax的使用

    一.AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. a).AJAX = 异步 JavaScript 和 XML. b).AJAX 是一种用于创建快速动态网页的技术. 通过在后 ...

  5. Swift 4 关于Darwin这个Module

    大家在做app或者framework的时候经常会用到生成随机数的方法arc4random系列,或者取绝对值abs()等.所以我有一次好奇的想看看在Developer Document里 是怎么描述这些 ...

  6. 读取FTP上的某个文本文档内容到本地

    /// <summary> /// 读取FTP服务器文本内容 /// </summary> /// <param name="strPath"> ...

  7. java中import详解

    前言 import与package机制相关,这里先从package入手,再讲述import以及static import的作用. package package名称就像是我们的姓,而class名称就像 ...

  8. [精品书单]3D打印机课程设计

    3D打印机整个绘图过程........... 三维图 工程图 编程

  9. Appnium-API-Status

    Status Java:// TODO Python:selenium.webdriver.common.utils.is_url_connectable(port) Description Retu ...

  10. Cardinality

    Cardinality: 优化器在计算成本的时候,需要从统计信息中取得数据,然后去估计每一步操作所涉及的行数,叫做Cardinality. 比如,一张表T有1000行数据,列COL1上没有直方图,没有 ...