草庐IT

some_props

全部标签

javascript - React 路由器 - 将路由上的 Prop 传递给子组件

有人可以告诉我最好的方法吗?我想将页面标题Prop从我的路线传递到我的标题子组件中。这是我的路线:varsampleApp=React.createClass({render:function(){return();},});varroutes=();Router.run(routes,function(Handler){varmountNode=document.getElementById('app');React.render(,mountNode);});我想像这样在路由中传递我的页面标题作为Prop:到我的头部组件:varHeader=React.createClass({r

javascript - `this.some_property` 在匿名回调函数中变为未定义

所以我不太明白为什么变量this.tasks在我的目标对象中的添加事件监听器中变得未定义。我觉得它可能与异步编程有关(我仍然不完全理解)。抱歉,我是一个JS菜鸟,但如果你们能向我解释我做错了什么,以及什么可能是更好的解决方案,那就太棒了!谢谢。functionGoal(name){this.gDiv=document.createElement('div');this.name=name||"goal";this.tasks=document.createElement('ul');//Setsthestylingandcontentandaddsittotheparentelemen

javascript - ReactJs this.props.router 未定义

你好,我正在学习Reactjs,我遇到了一个问题。当我尝试使用React路由器更改回主页时,出现以下错误:UncaughtTypeError:Cannotreadproperty'push'ofundefined这是我的代码,如您所见,我正在调用导航函数:我的带有路由器的client.js:如果我将this.props.router.push('/');替换为this.props.history.push('/');它工作正常.可能是什么问题? 最佳答案 您缺少调用super()的构造方法。super()调用父类的构造函数,需要将父

javascript - react this.props.params undefined

我无法通过id到我的产品页面,我尝试了所有方法并搜索了答案,但它仍然不起作用。这是我的index.js:importReactfrom"react";import{render}from"react-dom";import{Router,Route,IndexRoute,hashHistory}from"react-router";import{Menu}from'./components/Menu';import{MainPage}from'./components/MainPage';import{DetailsProduct}from'./components/DetailsPr

javascript - 将类型定义添加到将 props 注入(inject)组件的 HOC

我有一个以下列方式(无类型)实现的“高阶组件”。constThemeable=(mapThemeToProps)=>{return(WrappedComponent)=>{constthemedComponent=(props,{theme:appTheme})=>{return}themedComponent.contextTypes={theme:PropTypes.object};returnthemedComponent;}}总结一下它的作用,它需要一个mapThemeToProps函数。这将接收通过合并defaultTheme(由我的库提供)和appTheme(由ThemeP

javascript - 将 Flow 用于样式化组件 Props

所以我一直在研究JavaScript中的类型系统,大部分情况下一切正常,但是样式组件存在问题。我似乎找不到将流程应用于样式化组件的Prop的好方法。到目前为止,我看到的唯一解决方案是:exporttypeButtonPropTypes=ReactPropTypes&{styleType:'safe'|'info'|'warning'|'danger'|'link',isPill:boolean,isThin:boolean,};exportconstButtonStyled=styled.button`${generateBaseStyles}${hoverStyles}${fillS

javascript - 正确解构整个组件的 this.props

我今天遇到一个问题,考虑以下组件:exportdefaultclassInputextendsReact.Component{someFunction(){console.log(this.props.value)}render(){const{type,value,required}=this.propsreturn()}}我成功地解构了this.props并且可以在渲染中使用它们,但是如果我需要在它之外使用prop值怎么办,即在someFunction()我我不确定如果我移出constant{...}并在exportdefaultclassInputextendsReact.Com

javascript - React props.children 不是数组

根据reactdocs,如果一个组件有多个child,this.props.children应该是一个数组。我有以下组件:exportclassTwoextendsReact.Component{componentDidMount(){console.log(Array.isArray(this.props.children));//false}render(){return({this.props.children});}};我在另一个组件的render()方法中将child传递给它:为什么this.props.children不是数组?更重要的是,我怎样才能让它成为一个?

javascript - Reactjs 将方法作为 Prop 传递给 child

有没有办法将当前类的方法作为props传递给子类举个例子;varSignupModal=React.createClass({mixins:[CheckMixin],getInitialState:function(){return{'wizardstate':0}},setWizardState:function(state){varthat=this;switch(state){case0:that.setState({'wizardstate':0});break;case1:that.setState({'wizardstate':1});break;case2:that.se

javascript - 此警告消息是什么意思? 'img elements must have an alt prop, either with meaningful text, or an empty string for decorative images'

为什么我会收到此警告?warning:imgelementsmusthaveanaltprop,eitherwithmeaningfultext,oranemptystringfordecorativeimagesjsx-a11y/img-has-alt它显示第13行,但没有使用任何Prop。 最佳答案 这意味着当您在HTML中创建图像时,为了屏幕阅读器和文本浏览器的利益,您应该包含一个alt属性。 关于javascript-此警告消息是什么意思?'imgelementsmusthave