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

网站建设 蜂图网络wordpress做的视听网站

网站建设 蜂图网络,wordpress做的视听网站,太原今天最新通知,欧美一级a做爰片免费网站state 和 props 主要的区别在于 props 是不可变的#xff0c;而 state 可以根据与用户交互来改变。 所以#xff0c;有些容器组件需要定义 state 来更新和修改数据。 而子组件只能通过 props 来传递数据。 props 使用 Demo.js #xff1a; import React from reactfunct…state 和 props 主要的区别在于 props 是不可变的而 state 可以根据与用户交互来改变。 所以有些容器组件需要定义 state 来更新和修改数据。 而子组件只能通过 props 来传递数据。 props 使用 Demo.js import React from reactfunction Demo (props) {return (divh1name: {props.name}/h1h1message: {props.message}/h1h1phone: {props.phone}/h1/div) }export default Demo在 App.js 中引入组件 import ./assets/css/App.css; import Demo from ./components/Demofunction App () {return (div classNameAppDemo nameindex message哈哈哈 phone12312 //div); }export default App;页面效果 默认 Props 可以通过组件类的 defaultProps 属性为 props 设置默认值 !DOCTYPE html html head meta charsetUTF-8 / titleReact demo/title script srchttps://cdn.staticfile.org/react/16.4.0/umd/react.development.js/script script srchttps://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js/script script srchttps://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js/script /head bodydiv idexample/div script typetext/babel class HelloMessage extends React.Component {render() {return (divh1name: {this.props.name}/h1h1phone: {this.props.phone}/h1h1message: {this.props.message}/h1/div);} }HelloMessage.defaultProps {message: 我是props.message的默认值 };const element HelloMessage nameindex phone12312/;ReactDOM.render(element,document.getElementById(example) ); /script/body /html页面效果 组合使用 State 和 Props !DOCTYPE html html head meta charsetUTF-8 / titleReact Demo/title script srchttps://cdn.staticfile.org/react/16.4.0/umd/react.development.js/script script srchttps://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js/script script srchttps://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js/script /head bodydiv idexample/div script typetext/babelclass Demo extends React.Component {constructor() {super();this.state {name: xiaoming,msg: https://www.baidu.com}}render() {return (divName name{this.state.name} /Link site{this.state.msg} //div);} }class Name extends React.Component {render() {return (h1{this.props.name}/h1);} }class Link extends React.Component {render() {return (a href{this.props.site}{this.props.site}/a);} }ReactDOM.render(Demo /,document.getElementById(example) ); /script/body /html页面效果 上面实例在父组件中设置 state 并通过在子组件上使用 props 将其传递到子组件上。在 render 函数中, 设置 name 和 site 来获取父组件传递过来的数据。 Props 验证 Props 验证使用 propTypes可以保证应用组件被正确使用React.PropTypes 提供很多验证器 (validator) 来验证传入数据是否有效。当向 props 传入无效数据时JavaScript 控制台会抛出警告。 类型验证 !DOCTYPE html html head meta charsetUTF-8 / titleReact demo/title script srchttps://cdn.staticfile.org/react/16.4.0/umd/react.development.js/script script srchttps://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js/script script srchttps://cdn.staticfile.org/prop-types/15.6.1/prop-types.js/script script srchttps://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js/script /head bodydiv idexample/div script typetext/babel var title this is a title; class Demo extends React.Component {render() {return (h1Hello, {this.props.title}/h1);} }Demo.propTypes {title: PropTypes.string }; ReactDOM.render(Demo title{title} /,document.getElementById(example) ); /script/body /html以上实例创建一个 Demo 组件属性 title 是必须的且是字符串非字符串类型会自动转换为字符串。 页面效果 当修改 title 的值为其他类型时如下 var title true运行代码会抛出错误 是否为空验证 任意类型加上 isRequired 来使 prop 不可空。 将 Demo title{title} / 修改为 Demo / 然后修改校验 Demo.propTypes { title: PropTypes.string } 为如下 Demo.propTypes {title: PropTypes.string.isRequired };运行代码会抛出错误
http://www.dnsts.com.cn/news/71781.html

相关文章:

  • 太原网站设计开发公司安平县英文网站建设
  • 网站建设板块如何分类没有网站域名备案
  • 酒类网站建设方案案免费设计室内装修网址
  • asp汽车销售公司网站源码 4s店网站源码 汽车网站建设 完整无1网站建设公司
  • 昆明网站网站建设成全视频免费高清观看在线动漫
  • 如何查网站是哪家公司做的网站建设语言都有什么
  • 竞价网站做推广微商城手机网站制作公司
  • 图书馆网站开发的前期准备网页报价
  • 加强两微一端和门户网站建设网站静态页
  • 网站改版模版凡客诚品是什么牌子
  • 网站建设板块免费下载wordpress内链
  • 最权威的排行榜网站wordpress termux
  • 泉州网站建设方案优化如何建一个视频网站
  • asp网站制作软件京东商城网站建设目的
  • 做个网站大概多少钱网站注册时间查询
  • 网站建设登记表深圳网站建设吗
  • 做网站先学什么小松建设官方网站
  • 做301重定向会影响网站权重吗网站建设 销售
  • 黄山北京网站建设wordpress瀑布主题
  • 泰州网站设计哪家好东莞市seo网络推广报价
  • 南阳建设网站招聘黑黑网站
  • 做网站需准备些什么问题一般网站图标是用什么做的
  • 无锡网站建设哪家做的比较好山东烟台最新消息今天
  • 官网网站备案手机编程教程
  • wordpress 主页地址函数安卓优化大师旧版本
  • 制作京东一样的网站写wordpress php文件
  • 建个电子商务网站多少钱徐州经济开发区网站
  • 可信网站认证 技术支持单位百度怎么免费推广
  • wordpress建站怎么样域名及网站建设实训
  • 微商城手机网站内部网站建设、