【发布时间】:2017-08-09 21:27:27
【问题描述】:
我是 React 新手。我对Angular2+更熟悉。在 Angular 中,每个组件都有一个单独的 html 文件。但是,在 React 中,我看到渲染函数本身包含 html 模板。例如,
import React, { Component } from 'react';
class HelloWorld extends Component {
render() {
return (
<h2> Hello World </h2>
);
}
}
export default HelloWorld;
嗯,我想拍
<h2> Hello World </h2>
在js文件之外,放在一个单独的html中,导入html文件来渲染函数,例如
render() {
return (
import content of helloworld.html
);
}
你知道怎么做吗?
【问题讨论】:
-
通过保持组件小而轻,并将逻辑提取到智能组件中,应该不需要这样做。这是 React 开发人员的有意选择。您想这样做是有特殊原因还是只是因为习惯?
标签: reactjs