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

网站空间购买官方品牌seo推广咨询

网站空间购买官方,品牌seo推广咨询,专业做外贸英文公司网站,什么是网络营销促销?目录 举例说明1. 使用 class 定义2. 使用函数定义2.1 使用普通函数2.2 使用函数组件 举例说明 比如我们要定义一个计数器 Counter,它包含一个 label 和一个 button,计数器的初始值由外部传入,点击 button 计数加 1: 这虽然是个简单组件&…

目录

  • 举例说明
  • 1. 使用 class 定义
  • 2. 使用函数定义
    • 2.1 使用普通函数
    • 2.2 使用函数组件

举例说明

比如我们要定义一个计数器 Counter,它包含一个 label 和一个 button,计数器的初始值由外部传入,点击 button 计数加 1:

在这里插入图片描述

这虽然是个简单组件,但却包含了 React 定义组件的两大核心点:

  1. 属性由外部传入
  2. 状态由内部控制

组件样式:

// counter样式
const counterStyle = {backgroundColor: "orange",width: "100px",height: "100px",borderRadius: "10px",display: "flex",flexDirection: "column",alignItems: "center",justifyContent: "center",
} as React.CSSProperties;

使用组件:

<Counter initialCount={6} />

1. 使用 class 定义

// 属性
type Props = {// 初始countinitialCount: number;
};// 状态
type State = {count: number;
};// 计数器
class Counter extends Component<Props, State> {constructor(props: Props) {super(props);this.state = {count: props.initialCount,};}render() {return (<div style={counterStyle}><p>count={this.state.count}</p><buttononClick={() => {this.setState({count: this.state.count + 1,});}}>1</button></div>);}
}

2. 使用函数定义

2.1 使用普通函数

// 属性
type Props = {// 初始countinitialCount: number;
};// 计数器
function Counter(props: Props) {const [count, setCount] = useState(props.initialCount);return (<div style={counterStyle}><p>count={count}</p><buttononClick={() => {setCount(count + 1);}}>1</button></div>);
}

注:此函数返回的类型是 JSX.Element

2.2 使用函数组件

// 属性
type Props = {// 初始countinitialCount: number;
};// 计数器
const Counter = (props: Props) => {const [count, setCount] = useState(props.initialCount);return (<div style={counterStyle}><p>count={count}</p><buttononClick={() => {setCount(count + 1);}}>1</button></div>);
};

注:此函数返回的类型是 JSX.Element
若需要,可以指定函数返回的具体类型:

// 属性
type Props = {// 初始countinitialCount: number;
};// 计数器
const Counter: React.FC<Props> = (props) => {const [count, setCount] = useState(props.initialCount);return (<div style={counterStyle}><p>count={count}</p><buttononClick={() => {setCount(count + 1);}}>1</button></div>);
};

此时函数的返回值类型是 React.FC<Props>

http://www.ds6.com.cn/news/41052.html

相关文章:

  • 查询网站所有死链接培训学校
  • 工作站做网站上海谷歌seo公司
  • wordpress主题 直接拖拽式建站外贸展示型网站建设公司
  • 常州高端网站定制公司网络销售新手入门
  • 华强北设计网站建设合肥关键词优化平台
  • 多用户旅游网站开发培训班有哪些
  • 动漫设计与制作主修课程南昌seo排名公司
  • 微信小程序可以做音乐网站吗推广怎么推
  • 常用来做网站的首页软文有哪些推广渠道
  • 网站建设一个月做十单哪个公司网站设计好
  • 学做网站培训机构网络营销策划师
  • 投票网站建设营销方式有哪几种
  • drupal与wordpressseo优化服务是什么
  • 网站空间上传工具电商沙盘seo裤子关键词
  • 域名注册好了如何做网站扬州百度seo公司
  • 成都官方网站建设什么搜索引擎搜索最全
  • 临沂市住房和城乡建设委员会网站合肥seo推广排名
  • wordpress视频站插件做灰色词seo靠谱
  • 北京建设规划委员会网站黑帽seo技术有哪些
  • 昆明网站排名优化公司手机营销推广方案
  • 如皋网站建设公司教程seo推广排名网站
  • 男女视频做爰的网站百度公司的发展历程
  • 华强北网站建设网络seo培训
  • 个人可以做自媒体网站吗关键词林俊杰歌词
  • 北京建工招标平台seo网站优化培训怎么样
  • 怎么做免费推广网站营销软文800字范文
  • 2015网站排名搜狗竞价推广效果怎么样
  • 影视网站怎么做原创网络宣传的好处
  • 广告传媒公司网站世界军事新闻
  • 物流手机网站模板免费个人网站制作