React——使用React脚手架搭建工程

一、使用create-react-app安装

# 使用yarn安装react项目
yarn create react-app react-study

# 如果使用yarn创建react项目报错
npm install -g create-react-app
create-react-app react-study

二、VSCode开发环境配置

打开设置,搜索emmet
在这里插入图片描述
添加如下代码
在这里插入图片描述

"emmet.includeLanguages": {
      "javascript": "javascriptreact"
    }

三、Vscode插件安装

1.ESLint:代码风格检查
2.ES7 React/Redux/GraphQL/React-Native snippets:快速代码编写
3.React Developer Tools:浏览器插件,安装在浏览器上,可以去谷歌商店进行安装

四、jsx的语法的一些特性

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
const a = 1234, b = 2345;
const htmlContent = `<div>我是一个div</div><p>我是一个p标签</p>`;
const div = (
  <>
    {/* 这是注释,下面的null、undefined、false都不会在页面上显示,而且jsx必须要有一个根节点,注释都不能和根节点平级 */}
    { null }
    { undefined }
    { false }
    { /* jsx中元素的属性使用小驼峰命名法,某个表达式作为元素属性时,千万不要写双引号,直接大括号 */ }
    { /* 由于class与关键字重复,所有,元素的class属性是使用className代替 */ }
    { /* style在jsx中不能使用字符串了,需要使用对象,第一对{}表示是一个jsx表达式,第二对{}表示一个对象 */ }
    <div className="div" style={{
      fontSize: "30px",
      color: "red"
    }}>
      {a} * {b} = {a * b}
    </div>
    { /* 防止注入攻击,所以jsx会默认将字符串自动编码后展示在页面上,所以如果想将字符串按dom元素进行展示的话,需要使用到dangerouslySetInnerHTML */ }
    <div dangerouslySetInnerHTML={{__html: htmlContent}}></div>
  </>

)
root.render(
  div
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值