草庐IT

prop-types

全部标签

javascript - [Vue 警告] : Invalid prop: type check failed for prop "X". 预期,得到字符串

给定这个Vue2组件:Vue.component('read-more',{props:{'text':String,'clamp':{type:String,default:'ReadMore'},'less':{type:String,default:'ReadLess'},'length':{type:Number,default:100}},template:`{{truncate(text)}}=length"@click="toggle()">{{clamp}}{{text}}=length">{{less}}`,methods:{truncate(string){if(s

javascript - 哪些浏览器支持在 input[type ="file"] 元素上触发点击事件?

根据https://developer.mozilla.org/en/Using_files_from_web_applications,StartinginGecko2.0(Firefox4/Thunderbird3.3/SeaMonkey2.1),youcanhidetheadmittedlyuglyfileelementandpresentyourowninterfaceforopeningthefilepickeranddisplayingwhichfileorfilestheuserhasselected.像这样(使用jQuery):$('a.upload').click(f

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 - typescript 键盘事件 : argument of type 'Event' is not assignable to parameter of type 'KeyboardEvent'

即使代码运行完美,我也会出现以下错误:"TS2345:Argumentoftype'Event'isnotassignabletoparameteroftype'KeyboardEvent'.Property'altKey'ismissingintype'Event'."//InaClasspubliclistenTo=(window:Window)=>{['keydown','keyup'].forEach(eventName=>{window.addEventListener(eventName,e=>{this.handleEvent(e);//{const{key}=event

javascript - Node : How return different content types with same response (text and image)?

我正在尝试学习nodejs,我认为最好的方法是尝试在不使用express或任何其他非核心模块的情况下做一些事情。我坚持尝试同时发送一些文本和图像。我正在尝试的代码是:varhttp=require('http');varfs=require('fs');varserver=http.createServer(function(request,response){fs.readFile('my_pic.jpg',function(error,file){response.writeHead(200,{'content-type':'text/html'});response.write(

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 - 使用: and => for the return type with a TypeScript function?有什么区别

我有以下代码:///functionaddThemePrototypes(){vartemplateSetup=newArray();$.fn.addTemplateSetup=function(func,prioritary){if(prioritary){templateSetup.unshift(func);}else{templateSetup.push(func);}};}有人能告诉我为什么要用=>void来声明吗?interfaceJQuery{addTemplateSetup:(func:Function,priority:bool)=>void;}我想我对如何从java

javascript - 执行 Action 时 redux 出错 : Uncaught type error: cannot read property 'type' of undefined

刚刚接触React。我想这是一个基本问题,但我不明白为什么reducer没有被解雇或更新状态:我的HomeView.js:....const{localeChange,counter,locale}=this.propsreturn(increment(7)}>Increment.....)constmapStateToProps=(state)=>({locale:state.locale,counter:state.counter})exportdefaultconnect(mapStateToProps,{localeChange,increment})(HomeView)我的r