草庐IT

sys_prop

全部标签

javascript - React 中的 Constructor(props) 和 super(props) VS constructor() 和 super()

我知道这个问题被问过很多次了,但还是不清楚。很多人只是说:Passpropstoconstructorifyouwanttoaccessthis.propsthereonemoreexampleoftheanswer官方文档说Classcomponentsshouldalwayscallthebaseconstructorwithprops.,但如果我们不将props传递给constructor,除了构造函数之外,我们仍然会在任何地方都有this.props。同样来自reactsourcecode我们可以看到React.Component的源代码函数ReactComponent(pro

javascript - Enzyme 在浅层渲染的 React 组件上为 prop 返回 null

问题我刚刚开始进行enzyme和react测试。我正在尝试让enzyme与karma和webpack在一个简单的react组件上一起工作。我的问题是包装器上的prop()返回null,我不确定为什么。Greeter.jsimportReactfrom'react';/**Atrivialcomponentweaddedwhiletryingtogetthereacttestingworking**/exportdefaultclassGreeterextendsReact.Component{constructor(props){super(props);this.state={nam

javascript - 如何使用 flowtype 在组件的 react 上下文中定义 Prop ?

使用flowtype时在context中定义一个Prop这样//@flowtypeMyType=Object;classCustomViewextendsReact.Component{staticchildContextTypes={someProp:MyType}getChildContext(){return{someProp:this.props.someProp};}}我收到以下错误:CustomView:typespecificationofchildcontextsomePropsisinvalid;thetypecheckerfunctionmustreturnnull

javascript - Vue.js : "TypeError: Cannot set property props of#<Object> which has only a getter"

我正在尝试实例化一个Vue组件,但出现错误:[Vuewarn]:Errorinrender:"TypeError:Cannotsetpropertypropsof#whichhasonlyagetter"(foundin)我也在使用库vuedraggable但我认为这个问题更多的是Vue问题而不是vuedraggable问题。下面是我的代码。这里是draggable-list.vue可拖动列表.jsconstdraggable=require("vuedraggable");module.exports={name:"draggable-list",components:{dragga

javascript - <BrowserRouter> 忽略 history Prop

我使用的是React路由在线类(class)中的以下代码:import{Router,Route,browserHistory}from'react-router';ReactDOM.render(,document.getElementById('root'));它给了我以下错误'react-router'doesnotcontainanexportnamed'browserHistory'.我做了一些研究,发现我使用的是ReactRouterv4,而上面的代码是针对v3的,所以我发现我应该使用而不是所以我将代码更改为:import{BrowserRouter,Route,Switc

javascript - 用 enzyme react 测试组件 Prop 变化

我正在修改此处找到的示例:https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/setProps.mdclassFooextendsReact.Component{render(){return({}}/>);}}it('shouldpassanddoesnot',()=>{constwrapper=mount();expect(wrapper.find('.foo').html()).toBe(``);wrapper.setProps({name:'bar'});expect(wrapper.find('

javascript - 使用 react-router-redux 时未定义 this.props.children

我遵循了githubpage上的react-router-redux示例,但是当我尝试通过{this.props.children}到IndexRoute我尝试记录它,它是未定义的。我通过控制台得到的唯一错误是Warning:Youshouldnotuseandinthesameroute;willbeignored,通过谷歌搜索这个错误,它只是人们说忽略它的那些错误之一,因为它不影响任何代码(出于某种原因)。package.json...."react":"^0.14.7","react-redux":"^4.4.0","react-router":"^4.0.0","react-r

javascript - 尝试通过 Vue.js 中的渲染传递 Prop 并观看它们

我在使用vue.js中的CreateElement/render将Prop从父级向下传递到创建的子级时遇到问题,然后再观看它。这是我的父组件Vue.component('my-drawing',MyDrawing)newVue({el:'#drawing',mounted(){Bus.$on('emitColorSelection',(emitString)=>{console.log("insidesocket.js/my-drawingandemitStringis",emitString);this.useColor=emitString;console.log('insides

javascript - 如何在 this.props.children 中访问 React 对象的类名

在this.props.children中有一些子组件的React组件渲染方法中。如何获取每个child的组件(类)名称以区分它们?React.Children.map(this.props.children,function(child){//howcanIgettheclassnameofachildorsomeotheridentifier}) 最佳答案 警告:如果使用缩小,这将无法在生产中使用在ES6中,每个函数的名称都存储在属性function.name中所以你可以用importReactfrom'react'...get

javascript - Svelte 等同于 React 的 props.children?

我在svelte3的任何地方都找不到这个功能。我希望它是这样的..App.svelteCan'tconnecttotheserver!`Error.svelte{props.children}我希望App.svelte显示:Can'tconnecttotheserver!我只知道如何使用React的props.children来做到这一点。 最佳答案 您可以使用slot.它是svelte提供的一个组件。您可以在您的组件中使用它。传递给组件的任何内容都将代替插槽呈现在你的error.svelte中试试这个