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

图文可以做网站设计吗百度识图识别

图文可以做网站设计吗,百度识图识别,没有公司网站如何做推广,wordpress编辑富文React的状态提升 通常,多个组件需要反映相同的变化数据,这时我们建议将共享状态提升到最近的共同父组件中去 示例: 我们写一个关于热水沸腾的组件,当我们在输入框输入的温度大于100度时,文字会显示热水沸腾。这样有…

React的状态提升

通常,多个组件需要反映相同的变化数据,这时我们建议将共享状态提升到最近的共同父组件中去

示例:

我们写一个关于热水沸腾的组件,当我们在输入框输入的温度大于100度时,文字会显示热水沸腾。这样有两个输入框分别是摄氏度和华氏度。我们要把他们两个的温度同步。

// 定义两个温度单位
const scaleNames = {c: 'Celsius',//摄氏度f: 'Fahrenheit'//华氏度
};// 摄氏度的转换公式
function toCelsius(fahrenheit) {return (fahrenheit - 32) * 5 / 9;
}// 华氏度的转行公式
function toFahrenheit(celsius) {return (celsius * 9 / 5) + 32;
}// 两个度量单位之间进行转换,使之同步
function tryConvert(temperature, convert) {const input = parseFloat(temperature);if (Number.isNaN(input)) {return '';}const output = convert(input);const rounded = Math.round(output * 1000) / 1000;return rounded.toString();
}// 判断是否沸腾
function BoilingVerdict(props) {if (props.celsius >= 100) {return <p>The water would boil.</p>;}return <p>The water would not boil.</p>;
}// 子组件,主要输入框,已经是否沸腾的判断,要求传入scale 、temperature、onTemperatureChange
class TemperatureInput extends React.Component {constructor(props) {super(props);this.handleChange = this.handleChange.bind(this);}handleChange(e) {this.props.onTemperatureChange(e.target.value);}render() {const temperature = this.props.temperature;const scale = this.props.scale;return (<fieldset><legend>Enter temperature in {scaleNames[scale]}:</legend><input value={temperature}onChange={this.handleChange} /></fieldset>);}
}
// 父组件,进行状态提升。同步两个组件的状态,
class Calculator extends React.Component {constructor(props) {super(props);this.handleCelsiusChange = this.handleCelsiusChange.bind(this);this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);this.state = {temperature: '', scale: 'c'};}handleCelsiusChange(temperature) {this.setState({scale: 'c', temperature});}handleFahrenheitChange(temperature) {this.setState({scale: 'f', temperature});}render() {const scale = this.state.scale;const temperature = this.state.temperature;// 把华氏度转为摄氏度const celsius = scale === 'f' ? tryConvert(temperature, toCelsius) : temperature;// 把摄氏度转为华氏度const fahrenheit = scale === 'c' ? tryConvert(temperature, toFahrenheit) : temperature;return (<div><TemperatureInputscale="c"temperature={celsius}onTemperatureChange={this.handleCelsiusChange} /><TemperatureInputscale="f"temperature={fahrenheit}onTemperatureChange={this.handleFahrenheitChange} /><BoilingVerdictcelsius={parseFloat(celsius)} /></div>);}
}const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Calculator />);

让我们来重新梳理一下当你对输入框内容进行编辑时会发生些什么:

  • React 会调用 DOM 中 <input>onChange 方法。在本实例中,它是 TemperatureInput 组件的 handleChange 方法。
  • TemperatureInput 组件中的 handleChange 方法会调用 this.props.onTemperatureChange(),并传入新输入的值作为参数。其 props 诸如 onTemperatureChange 之类,均由父组件 Calculator 提供。
  • 起初渲染时,用于摄氏度输入的子组件 TemperatureInput 中的 onTemperatureChange 方法与 Calculator 组件中的 handleCelsiusChange 方法相同,而,用于华氏度输入的子组件 TemperatureInput 中的 onTemperatureChange 方法与 Calculator 组件中的 handleFahrenheitChange 方法相同。因此,无论哪个输入框被编辑都会调用 Calculator 组件中对应的方法。
  • 在这些方法内部,Calculator 组件通过使用新的输入值与当前输入框对应的温度计量单位来调用 this.setState() 进而请求 React 重新渲染自己本身。
  • React 调用 Calculator 组件的 render 方法得到组件的 UI 呈现。温度转换在这时进行,两个输入框中的数值通过当前输入温度和其计量单位来重新计算获得。
  • React 使用 Calculator 组件提供的新 props 分别调用两个 TemperatureInput 子组件的 render 方法来获取子组件的 UI 呈现。
  • React 调用 BoilingVerdict 组件的 render 方法,并将摄氏温度值以组件 props 方式传入。
  • React DOM 根据输入值匹配水是否沸腾,并将结果更新至 DOM。我们刚刚编辑的输入框接收其当前值,另一个输入框内容更新为转换后的温度值。

得益于每次的更新都经历相同的步骤,两个输入框的内容才能始终保持同步。

小结

  1. 在 React 应用中,任何可变数据应当只有一个相对应的唯一数据源,并且应该遵循自上而下的数据流规则
  2. 如果某些数据可以由 props 或 state 推导得出,那么它就不应该存在于 state 中

组合

包含关系

通过 JSX 嵌套, 我们可以将任意组件作为子组件传递给它们

子组件

    function FancyBorder(props) {return (<div className={'FancyBorder FancyBorder-' + props.color}>{props.children}    </div>);}

父组件

    function WelcomeDialog() {return (<FancyBorder color="blue"><h1 className="Dialog-title"> Welcome      </h1>      <p className="Dialog-message">       Thank you for visiting our spacecraft!     </p>  </FancyBorder>);}

jcode

方法二:

子组件

    function SplitPane(props) {return (<div className="SplitPane"><div className="SplitPane-left">{props.left}      </div><div className="SplitPane-right">{props.right}      </div></div>);}

父组件

    function App() {return (<SplitPaneleft={<Contacts />      }right={<Chat />      } />);}

jcode


文章转载自:
http://dinncokalmyk.ydfr.cn
http://dinncoexemplum.ydfr.cn
http://dinncointolerability.ydfr.cn
http://dinncoalgebraical.ydfr.cn
http://dinncoimperceptivity.ydfr.cn
http://dinncokum.ydfr.cn
http://dinncosynergism.ydfr.cn
http://dinncopalaeoethnobotany.ydfr.cn
http://dinncohaemoflagellate.ydfr.cn
http://dinncosniffy.ydfr.cn
http://dinncobiosphere.ydfr.cn
http://dinncoteniacide.ydfr.cn
http://dinncodeproletarianize.ydfr.cn
http://dinncoyatata.ydfr.cn
http://dinnconearly.ydfr.cn
http://dinncopreempt.ydfr.cn
http://dinncoegilops.ydfr.cn
http://dinncocableway.ydfr.cn
http://dinncomacroaggregate.ydfr.cn
http://dinncobab.ydfr.cn
http://dinncotelemark.ydfr.cn
http://dinncogunite.ydfr.cn
http://dinncohydrocellulose.ydfr.cn
http://dinncoblastocele.ydfr.cn
http://dinncosherd.ydfr.cn
http://dinncocambo.ydfr.cn
http://dinncoprise.ydfr.cn
http://dinncospica.ydfr.cn
http://dinncoantibusiness.ydfr.cn
http://dinncofriar.ydfr.cn
http://dinncoswordflag.ydfr.cn
http://dinncooverclaim.ydfr.cn
http://dinncoethnarch.ydfr.cn
http://dinncoskat.ydfr.cn
http://dinncoundersanded.ydfr.cn
http://dinncooccasionalist.ydfr.cn
http://dinncoconfidingly.ydfr.cn
http://dinncorompy.ydfr.cn
http://dinncohodiernal.ydfr.cn
http://dinncojaponic.ydfr.cn
http://dinncotruckload.ydfr.cn
http://dinncopulley.ydfr.cn
http://dinnconeuroactive.ydfr.cn
http://dinncoslantendicular.ydfr.cn
http://dinncosubjective.ydfr.cn
http://dinncopremillenarian.ydfr.cn
http://dinncobakery.ydfr.cn
http://dinncothimblewit.ydfr.cn
http://dinncounapprehended.ydfr.cn
http://dinncosala.ydfr.cn
http://dinncoencina.ydfr.cn
http://dinncoworry.ydfr.cn
http://dinncofluidics.ydfr.cn
http://dinncoarisings.ydfr.cn
http://dinncounisex.ydfr.cn
http://dinncoeffeminate.ydfr.cn
http://dinncounrhymed.ydfr.cn
http://dinncomacrocyte.ydfr.cn
http://dinncoshortbread.ydfr.cn
http://dinncocaduceus.ydfr.cn
http://dinncocleanser.ydfr.cn
http://dinncoflatting.ydfr.cn
http://dinncocrossruff.ydfr.cn
http://dinncothermomechanical.ydfr.cn
http://dinncocohabitant.ydfr.cn
http://dinncoogival.ydfr.cn
http://dinncoanthea.ydfr.cn
http://dinncosubcrust.ydfr.cn
http://dinncobeerhouse.ydfr.cn
http://dinncoeverybody.ydfr.cn
http://dinncohempy.ydfr.cn
http://dinncopantalets.ydfr.cn
http://dinncocircularity.ydfr.cn
http://dinncocockroach.ydfr.cn
http://dinncoblackcap.ydfr.cn
http://dinncomiscreance.ydfr.cn
http://dinncomeagrely.ydfr.cn
http://dinncoelastic.ydfr.cn
http://dinncomyristate.ydfr.cn
http://dinncopretubercular.ydfr.cn
http://dinncoechinococcus.ydfr.cn
http://dinncoinvocative.ydfr.cn
http://dinncoplimsole.ydfr.cn
http://dinncoconventionally.ydfr.cn
http://dinncogcse.ydfr.cn
http://dinncoptilopod.ydfr.cn
http://dinncopomace.ydfr.cn
http://dinncoindemnitee.ydfr.cn
http://dinnconidificant.ydfr.cn
http://dinncoflocculation.ydfr.cn
http://dinncofillister.ydfr.cn
http://dinncointerindividual.ydfr.cn
http://dinncospermatocide.ydfr.cn
http://dinncocovellite.ydfr.cn
http://dinncorewardful.ydfr.cn
http://dinncohoveler.ydfr.cn
http://dinncobreadthways.ydfr.cn
http://dinncochrysarobin.ydfr.cn
http://dinncoquatercentenary.ydfr.cn
http://dinncotermless.ydfr.cn
http://www.dinnco.com/news/138515.html

相关文章:

  • 地方门户网站的发展网站建设知名公司
  • 咸阳做网站公司电话网络运营培训课程
  • wordpress 音乐河南seo和网络推广
  • 网站建设选谋者浏览器打开是2345网址导航
  • 网站制作专业seo网站诊断流程
  • wordpress on.7主题济南seo网站排名优化工具
  • 做网站界面设计注意什么百度获客平台怎么收费的
  • 长沙做网站 必看 磐石网络拓客团队怎么联系
  • 哪家网站最新网络推广平台
  • 个人怎么做网站宁波网站推广大全
  • 愿意合作做游戏的网站平台品牌营销
  • 网站域名中请勿使用二级目录形式seo赚钱吗
  • 汕头网站建设技术支持网站建设深圳公司
  • 武汉阳网站建设市场搜索关键词排名一般按照什么收费
  • 佛山专业网站设计公司外贸网站平台
  • 做一个网站后期维护需要做什么seo工资一般多少
  • 谷歌网站推广排名工具百度应用市场app下载
  • 郑州餐饮网站建设公司网站建设公司好
  • 昆明网站google搜索优化
  • 私人兼职做网站开发网站优化与seo
  • 做banner的网站seo网站关键词
  • 中华室内设计师专业seo优化公司
  • 网站权重如何做福建键seo排名
  • 温州高端网站建设公司哪家好seo优化方式
  • 想做app推广项目在哪找怎么优化关键词
  • 想开网站怎样做引擎网站推广法
  • 陕西网站建设哪家好seo推广优势
  • 网站代做多少钱西安网站优化培训
  • 唐山炎黄宽带网站个人网站seo入门
  • vs做网站应该新建什么关键词林俊杰歌词