Open ufologist opened 8 years ago
为什么我npm run build 之后生成的build文件夹里的index.html 文件在浏览器内打开是空白的呢
@zhangolve 请再详细描述下你的情况, 否则我没有办法提供更多的建议.
针对你说的如下问题:
index.html 文件在浏览器内打开是空白的
这种情况下你最好通过 chrome devtools
查看下 index.html
是否正确引用了 npm run build
打包后的文件, 而且都是存在且正常的.
@ufologist 几个月以前的疑惑了,现在已经解决了,当时不是太懂打包之后的文件怎么用。其实是还需要对生成的文件进行引用的。当时并不懂,所以就提了问题。
最近上手了 create-react-app 工具, 大大降低了 React 的使用门槛, 扫清了 N 多搭建环境的障碍. 再也不必折腾 N 多工具就可以开启你的 React 之旅了(从此你再也不好意思说 React 好麻烦了)
以前你可能需要准备的环境有:
现在有了
create-react-app
, 你只需下面几个命令就够了下面正式开启我的 React 之旅
即 React Tutorial 学习笔记
React is all about modular, composable components.
For our comment box example, we'll have the following component structure:
We pass some methods in a JavaScript object to
React.createClass()
to create a new React component.The most important of these methods is called
render
which returns a tree of React components that will eventually render to HTML.The
<div>
tags are not actual DOM nodes; they are instantiations of React div components.React is safe. We are not generating HTML strings so XSS protection is the default.
You can return a tree of components that you (or someone else) built.
This is what makes React composable: a key tenet of maintainable frontends.
ReactDOM.render()
instantiates the root component, starts the framework, and injects the markup into a raw DOM element, provided as the second argument.The ReactDOM module exposes DOM-specific methods, while React has the core tools shared by React on different platforms (e.g., React Native).
It is important that ReactDOM.render remain at the bottom of the script for this tutorial. ReactDOM.render should only be called after the composite components have been defined.
Data passed in from a parent component is available as a 'property' on the child component. These 'properties' are accessed through
this.props
.We access named attributes passed to the component as keys on this.props and any nested elements as this.props.children.
That's React protecting you from an XSS attack. There's a way to get around it but the framework warns you not to use it:
props
are immutable: they are passed from the parent and are "owned" by the parent.To implement interactions, we introduce mutable
state
to the component.getInitialState()
executes exactly once during the lifecycle of the component and sets up the initial state of the component.componentDidMount()
is a method called automatically by React after a component is rendered for the first time.Controlled components
A Controlled component does not maintain its own internal state; the component renders purely based on props.
React attaches event handlers to components using a camelCase naming convention.
React.createClass() automatically binds each method to its component instance, obviating the need for explicit binding.
Autobinding and Event Delegation
最后奉上代码大家可以尝尝鲜