3 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
我知道你想用 React 創(chuàng)建一個(gè)簡(jiǎn)單的應(yīng)用程序。我建議你先讀一 https://kentcdodds.com/blog/how-to-react,然后再讀這個(gè):https://reactjs.org/tutorial/tutorial.html
可以通過在開始時(shí)導(dǎo)入腳本來創(chuàng)建 react 應(yīng)用程序,但這不是構(gòu)建 react 應(yīng)用程序的推薦方法。
完成上述帖子后,請(qǐng)?jiān)谀x擇的平臺(tái)上找到您選擇的好教程,無論是基于博客還是基于視頻。我可以舉出一些像udemy,前端大師,復(fù)數(shù)視覺,還有更多。

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊
看看 ReactJS 網(wǎng)站。
你應(yīng)該使用 Node 包管理器創(chuàng)建 React 應(yīng)用程序 npx create-react-app appName
或者應(yīng)該將反應(yīng)腳本鏈接到您的html
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
也不能重新定義文檔對(duì)象。這將引用您的網(wǎng)頁,您可以使用文檔對(duì)象訪問元素或 DOM(文檔對(duì)象模型)。

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
根據(jù) https://reactjs.org/docs/add-react-to-a-website.html,您需要在導(dǎo)入腳本之前將以下兩行添加到HTML文件中:
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
我不確定模塊加載是否會(huì)按照你想要的方式工作,而不使用像Create React App這樣的東西。您可以刪除導(dǎo)入語句,并且仍然可以在腳本中引用 React 和 ReactDOM。
例如:
'use strict';
const e = React.createElement;
class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
return 'You liked comment number ' + this.props.commentID;
}
return e(
'button',
{ onClick: () => this.setState({ liked: true }) },
'Like'
);
}
}
// Find all DOM containers, and render Like buttons into them.
document.querySelectorAll('.like_button_container')
.forEach(domContainer => {
// Read the comment ID from a data-* attribute.
const commentID = parseInt(domContainer.dataset.commentid, 10);
ReactDOM.render(
e(LikeButton, { commentID: commentID }),
domContainer
);
});
添加回答
舉報(bào)