美文网首页
ReactJS自习第叁夜

ReactJS自习第叁夜

作者: 行走的程序猿 | 来源:发表于2017-05-31 09:47 被阅读4次
    jsx
    • 传播属性 spread attribute
      将单独定义的属性对象变量作为组件的props
    const myProps = {
      a: 1,
      b: 2,
    }
    <myComponent {...myProps} />
    
    • jsx中写表达式和变量
      jsx中的表达式要用{}括起来。
    render() {
      const isLoggedIn = this.state.isLoggedIn;
      return (
        <div>
          {isLoggedIn ? (
            <LogoutButton onClick={this.handleLogoutClick} />
          ) : (
            <LoginButton onClick={this.handleLoginClick} />
          )}
        </div>
      );
    }
    
    renderFullName () {
      return `${this.props.firstName} ${this.props.lastName}`;
    }
    
    ES6 箭头函数

    非方法函数
    纯函数

    redux到底是啥
    react router

    每一个路由(Route)中声明的组件(比如 SignIn)在渲染之前都会被传入一些 props,具体是在源码中的 RoutingContext.js 中完成,主要包括:

    • history 对象,它提供了很多有用的方法可以在路由系统中使用,比如刚刚用到的 history.replaceState,用于替换当前的 URL,并且会将被替换的 URL 在浏览器历史中删除。函数的第一个参数是 state 对象,第二个是路径;
    • location 对象,它可以简单的认为是 URL 的对象形式表示,这里要提的是 location.state,这里 state 的含义与 HTML5 history.pushState API 中的 state 对象一样。每个 URL 都会对应一个 state 对象,你可以在对象里存储数据,但这个数据却不会出现在 URL 中。实际上,数据被存在了 sessionStorage 中;
    webstorm 2017.1.3 激活服务器

    http://idea.imsxm.com/

    相关文章

      网友评论

          本文标题:ReactJS自习第叁夜

          本文链接:https://www.haomeiwen.com/subject/dzhsxxtx.html