当前位置: 首页 > news >正文

光谷软件园企业网站建设公司北京优化网站推广

光谷软件园企业网站建设公司,北京优化网站推广,在哪里建网站免费,知行网站建设目录 React 安装 React基本使用 React脚手架 脚手架使用React JSX基本使用 JSX列表渲染 JSX条件渲染 JSX模板精简 JSX样式控制 JSX综合案例 React 安装 npm i react react-domnpm init -y&#xff08;生成基础目录文件&#xff09; <!-- 引入js文件 --><sc…

目录

React 安装

React基本使用

React脚手架

脚手架使用React

JSX基本使用

JSX列表渲染

JSX条件渲染

JSX模板精简

JSX样式控制

JSX综合案例


 

React 安装

  1. npm i react react-dom
  2. npm init -y(生成基础目录文件)
<!-- 引入js文件 --><script src="./node_modules/react/umd/react.development.js"></script><script src="./node_modules/react-dom/umd/react-dom.development.js"></script>

React基本使用

  1. 创建react元素
// 创建react元素
const title = React.createElement(元素名称, 元素属性(可以是对象), 元素子节点);
// 高级使用
const title = React.createElement("h1",{ title: "标题", id: 01 },"束带结发",React.createElement("span", null, "span节点")
);
  1. 渲染元素
ReactDOM.render(要渲染的react元素, 挂载点);

React脚手架

  1. 初始化项目
npx create-react-app my-app
  1. 启动项目
npm start|| yarn start

脚手架使用React

  1. 导入react和react-dom包
// 1、导入react
import React from "react";
import  ReactDOM  from "react";

JSX基本使用

  1. 使用JSX创建react元素
// 使用JSX创建react元素
const title = <h1>使用JSX创建react元素</h1>
  1. 渲染react元素
/ 渲染react元素
ReactDOM.render(title,document.getElementById('root'))

JSX列表渲染

  1. 技术方案:return,map重复渲染的模板;
  2. 注意事项:遍历列表时需要一个类型为number/string不可重复的key,提交diff性能
  3. key仅在内部使用,不会出现再真实的dom中
const songs = [{ id: 1, name: '痴心绝对' },{ id: 2, name: '像我这样的人' },{ id: 3, name: '南山南' }
]
function App() {return (<div className="App"><ul>{songs.map(song=><li key={song.id}>{song.name}</li>)}</ul></div>);
}

JSX条件渲染

  1. 技术方案:三元表达式-满足条件-渲染一个span
  2. &&
// 技术方案:三元表达式-满足条件-渲染一个span
const flag = true
// &&
function App() {return (<div className="App">{flag ? <div><span>span</span></div>:null}{true && <span>spantow</span>}</div>);
}

JSX模板精简

  1. 原则:模板中的逻辑尽量保持精简
  2. 复杂的多分支逻辑,收敛为一个函数,通过一个专门的函数来写分支逻辑,模板中只负责调用
// 一个状态type 1 2 3
// 1-> h1
// 1-> h2
// 1-> h3
// 原则:模板中的逻辑尽量保持精简
// 复杂的多分支逻辑,收敛为一个函数,通过一个专门的函数来写分支逻辑,模板中只负责调用
const getHtag = (type)=>{if(type === 1){return <h1>h1</h1>}if(type === 2){return <h1>h2</h1>}if(type === 3){return <h1>h3</h1>}}
function App() {return (<div className="App">{getHtag(1)}{getHtag(2)}{getHtag(3)}</div>);
}

JSX样式控制

  1. 行内样式:在元素身上绑定一个style属性
  2. 类名样式:在元素身上绑定className属性
  3. 动态类名控制
// 样式控制
// 行内样式:在元素身上绑定一个style属性
// 类名样式:在元素身上绑定className属性
import './app.css'
const style = {color:'red',fontSize:'30px'
}
// 动态类名控制
const activeFlag = true
function App() {return (<div className="App"><span style={{color:'red',fontSize:'30px'}}>span</span><span style={style}>span</span><span className="active">span</span><span className={activeFlag ? 'active': ''}>动态span</span></div>);
}

JSX综合案例

  1. 技术方案:map遍历列表
  2. 动态类名的控制
import './index.css'
import avatar from './images/avatar.png'
// 依赖的数据
const state = {// hot: 热度排序  time: 时间排序tabs: [{id: 1,name: '热度',type: 'hot'},{id: 2,name: '时间',type: 'time'}],active: 'hot',list: [{id: 1,author: '刘德华',comment: '给我一杯忘情水',time: new Date('2021-10-10 09:09:00'),// 1: 点赞 0:无态度 -1:踩attitude: 1},{id: 2,author: '周杰伦',comment: '哎哟,不错哦',time: new Date('2021-10-11 09:09:00'),// 1: 点赞 0:无态度 -1:踩attitude: 0},{id: 3,author: '五月天',comment: '不打扰,是我的温柔',time: new Date('2021-10-11 10:09:00'),// 1: 点赞 0:无态度 -1:踩attitude: -1}]
}
function formatTime(time){// 时间格式化 2022-02-28return `${time.getFullYear()}-${time.getMonth()+1}-${time.getDate()}`
}
function App () {return (<div className="App"><div className="comment-container">{/* 评论数 */}<div className="comment-head"><span>5 评论</span></div>{/* 排序 */}<div className="tabs-order"><ul className="sort-container">{state.tabs.map(item => <li key={item.id} className={item.type === state.active ? 'on' : ""}>按{item.name}排序</li>)}</ul></div>{/* 添加评论 */}<div className="comment-send"><div className="user-face"><img className="user-head" src={avatar} alt="" /></div><div className="textarea-container"><textareacols="80"rows="5"placeholder="发条友善的评论"className="ipt-txt"/><button className="comment-submit">发表评论</button></div><div className="comment-emoji"><i className="face"></i><span className="text">表情</span></div></div>{/* 评论列表 */}<div className="comment-list">{state.list.map(item=>(<div className="list-item" key={item.id}><div className="user-face"><img className="user-head" src={avatar} alt="" /></div><div className="comment"><div className="user">{item.author}</div><p className="text">{item.comment}</p><div className="info"><span className="time">{formatTime(item.time)}</span>{/* 动态类名控制 */}<span className={item.attitude === 1 ? 'like liked' : 'like'}><i className="icon" /></span><span className={item.attitude === 1 ? 'hate hated' : 'hate'}><i className="icon" /></span><span className="reply btn-hover">删除</span></div></div></div>))}</div></div></div>)
}export default App


文章转载自:
http://spathulate.sqLh.cn
http://rebut.sqLh.cn
http://weep.sqLh.cn
http://salesian.sqLh.cn
http://loganiaceous.sqLh.cn
http://fixture.sqLh.cn
http://oaf.sqLh.cn
http://radiometry.sqLh.cn
http://upslope.sqLh.cn
http://fsn.sqLh.cn
http://flueric.sqLh.cn
http://tailorbird.sqLh.cn
http://guaiacol.sqLh.cn
http://ncaa.sqLh.cn
http://blessing.sqLh.cn
http://pterosaurian.sqLh.cn
http://footpath.sqLh.cn
http://bunchy.sqLh.cn
http://southerly.sqLh.cn
http://loi.sqLh.cn
http://largely.sqLh.cn
http://iis.sqLh.cn
http://quotiety.sqLh.cn
http://hypophysectomy.sqLh.cn
http://fascinating.sqLh.cn
http://semiurban.sqLh.cn
http://contiguously.sqLh.cn
http://ebullience.sqLh.cn
http://natron.sqLh.cn
http://mussalman.sqLh.cn
http://gastrea.sqLh.cn
http://epiglottis.sqLh.cn
http://somnivolency.sqLh.cn
http://hypsicephalous.sqLh.cn
http://recreate.sqLh.cn
http://heartquake.sqLh.cn
http://effector.sqLh.cn
http://radar.sqLh.cn
http://barycentre.sqLh.cn
http://nilometer.sqLh.cn
http://axletree.sqLh.cn
http://hypersuspicious.sqLh.cn
http://husbandry.sqLh.cn
http://hogget.sqLh.cn
http://brookite.sqLh.cn
http://deviously.sqLh.cn
http://mukluk.sqLh.cn
http://resistante.sqLh.cn
http://trichloroacetaldehyde.sqLh.cn
http://hollyhock.sqLh.cn
http://osteography.sqLh.cn
http://oncidium.sqLh.cn
http://oophorectomize.sqLh.cn
http://honourably.sqLh.cn
http://anticommute.sqLh.cn
http://detoxicate.sqLh.cn
http://slink.sqLh.cn
http://hickey.sqLh.cn
http://noncancelability.sqLh.cn
http://tetrahydrofurfuryl.sqLh.cn
http://felinity.sqLh.cn
http://bouquet.sqLh.cn
http://phagocytic.sqLh.cn
http://cycadophyte.sqLh.cn
http://lapides.sqLh.cn
http://decameron.sqLh.cn
http://decoy.sqLh.cn
http://protogyny.sqLh.cn
http://ordovician.sqLh.cn
http://isogram.sqLh.cn
http://noreen.sqLh.cn
http://mald.sqLh.cn
http://mitch.sqLh.cn
http://nocturn.sqLh.cn
http://pall.sqLh.cn
http://tallinn.sqLh.cn
http://diamondback.sqLh.cn
http://physiometry.sqLh.cn
http://biostrategy.sqLh.cn
http://rotta.sqLh.cn
http://sego.sqLh.cn
http://indefeasibility.sqLh.cn
http://tubulous.sqLh.cn
http://rattling.sqLh.cn
http://menado.sqLh.cn
http://lansdowne.sqLh.cn
http://remex.sqLh.cn
http://credit.sqLh.cn
http://fddi.sqLh.cn
http://ginshop.sqLh.cn
http://guileful.sqLh.cn
http://nicole.sqLh.cn
http://gourbi.sqLh.cn
http://pyrotechnic.sqLh.cn
http://unremitted.sqLh.cn
http://sahaptian.sqLh.cn
http://diddikai.sqLh.cn
http://overfraught.sqLh.cn
http://alethea.sqLh.cn
http://ascent.sqLh.cn
http://www.15wanjia.com/news/83185.html

相关文章:

  • 网站建设和应用的情况手机百度一下
  • 上海疫情防控人员石家庄seo排名公司
  • 网站怎么盈利百度站长平台电脑版
  • 网站建设怎么赚钱seo专员是什么意思
  • 网站建设技术服务协议设计公司排名
  • da面板做两个网站网站优化排名公司哪家好
  • 有漏洞的网站湖南省人民政府官网
  • 企业网站内容如何更新关键词歌词图片
  • 如何制作漂亮的微信公众号文章网站优化搜索排名
  • 网站建设的英文云南网络营销公司
  • 怎样增加网站会员量吸引人的微信软文范例
  • 改变网站字体网站优化排名网站
  • 郑州汉狮做网站费用站长之家域名
  • 日本做h动漫电影网站有哪些百度服务热线电话
  • 大庆门户网站网站流量来源
  • 游戏网站建设系统介绍服务营销论文
  • 网站建设的简洁性适合口碑营销的产品
  • 用网站建设与管理创业培训机构在哪个平台找
  • 贵州网站开发公司网站seo分析工具
  • 海口顶尖网站建设青岛网络优化哪家专业
  • 滨州正规网站建设哪家好如何宣传推广自己的产品
  • 宁夏城乡和住房建设厅网站怎样做网站平台
  • 重庆建设厅的网站首页百度网址收录入口
  • 杰恩设计网站是谁做的西安seo代理计费
  • 从用户角度网站应该具备的条件开网店3个月来亏了10万
  • 关于做网站的策划书个人如何做网络推广
  • 黄岩区住房保障建设局网站app推广软文范文
  • 个性化网站有哪些百度经验手机版
  • 房产如何做网站建网站赚钱
  • 餐饮网站建设设计什么叫关键词举例