React Native开发React.jsReact Native开发经验集

react&node必须掌握的知识点

2018-12-01  本文已影响1人  全栈弄潮儿

react-router-redux

react-router按需加载

path
将匹配的路由,也就是以前的 path。

getComponent
对应于以前的 component 属性,但是这个方法是异步的,也就是当路由匹配时,才会调用这个方法。

require.ensure(dependencies, callback, chunkName)
这是 webpack 提供的方法,这也是按需加载的核心方法。第一个参数是依赖,第二个是回调函数,第三个就是上面提到的 chunkName,用来指定这个 chunk file 的 name。

如果需要返回多个子组件,则使用 getComponents 方法,将多个组件作为一个对象的属性通过 cb 返回出去即可。这个在官方示例也有,但是我们这里并不需要,而且根组件是不能返回多个子组件的,所以使用 getComponent。

indexRoute
用来设置主页,对应于以前的 <IndexRoute>。

注意这里的 indexRoute 写法, 这是个对象,在对象里面使用 getComponent。

childRoutes
这里面放置的就是子路由的配置,对应于以前的子路由们。我们将以前的 /baidu、/404 和 * 都拆了出来,接下来将分别为他们创建路由配置。

redux-thunk

Action

Action就是一个对象,一个必须带key为type的对象

Reducer

function count(state = 0, action) {
    switch (action.type) {
        case 'ADD':
            return state + 1;
        default:
            return state;
    }
}

Store

store是一个全局对象

将action和reducer以及state联系在一起,主要职责:

store引用reducer
reducer引用action

使用需要引用store和action

html-webpack-plugin

利用ejs模板的语法来动态插入各自页面的thunk和css样式

eg:

<!DOCTYPE html>
<html style="font-size:20px">
<head>
<meta charset="utf-8">
<title><%= htmlWebpackPlugin.options.title %></title>
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%=htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
<% } %>
</head>
<body>
<div id="app"></div>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script type="text/javascript" src="<%=htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
</body>
</html>

Promise缺点

CommonJS

es6模块

export

import

import()

import()的一些适用场合

import(f())
.then(...);

Class 的静态方法

Class 的静态属性和实例属性

class Foo {
}

Foo.prop = 1;
Foo.prop // 1

新提案:

class MyClass {
  myProp = 42;

  constructor() {
    console.log(this.myProp); // 42
  }
}
class MyClass {
  static myStaticProp = 42;

  constructor() {
    console.log(MyClass.myStaticProp); // 42
  }
}

new.target 属性

module.exports与exorts的区别

express中间件


更多angular1/2/4/5、ionic1/2/3、react、vue、微信小程序、nodejs等技术文章、视频教程和开源项目,请关注微信公众号——全栈弄潮儿

微信公众号.png

前端最火框架排行榜——小程序二维码

前端排行榜.png
上一篇 下一篇

猜你喜欢

热点阅读