草庐IT

prop-types

全部标签

javascript - 如何使用 TypeScript 为无状态、功能性 React 组件指定(可选)默认 Prop ?

我正在尝试在Typescript中创建一个带有可选props和defaultProps的无状态React组件(用于ReactNative项目)。这对于vanillaJS来说是微不足道的,但我对如何在TypeScript中实现它感到困惑。使用以下代码:importReact,{Component}from'react';import{Text}from'react-native';interfaceTestProps{title?:string,name?:string}constdefaultProps:TestProps={title:'Mr',name:'McGee'}constT

javascript - 在 .map 函数中使用 react Prop

这个问题在这里已经有了答案:Howtoaccessthecorrect`this`insideacallback(13个答案)关闭6年前。假设我的其中一个组件具有以下渲染功能。我从父元素传递了一个changeTid属性函数。父级:child:(我正在使用ES6类)render(){varRequestNodes=this.props.data.map(function(request){return();});return({RequestNodes});}我不能在我的map函数中使用this.props.changeTid,因为this没有引用我不需要的内容。我在哪里绑定(bind)

javascript - 使用 .prop 在 JQuery 中隐藏按钮(隐藏 : true)

我正在尝试弄清楚如何使用.prop(hidden:true)方法使用JQuery隐藏按钮。出于某种原因,在Chrome中,当我设置此值并查看html时,该按钮有一个隐藏元素,但该按钮在页面上仍然显示为可见。有什么想法吗? 最佳答案 按钮没有隐藏属性?$('button').hide();或$('button').toggle(true);//showsbutton$('button').toggle(false);//hidesbutton 关于javascript-使用.prop在JQ

javascript - 转移 { ..this.props } 但排除某些

是否可以将props向下传输到子组件,其中{..this.props}用于更简洁的语法,但是排除某些props,如className或id? 最佳答案 您可以使用解构来完成这项工作:const{className,id,...newProps}=this.props;//eslint-disable-line//`newProps`variabledoesnotcontain`className`and`id`properties由于此语法目前是ECMAScript提案(Rest/SpreadProperties),您需要转换代码以

javascript - 流: Dynamically generate string union types?

假设我有一个流类型Suit,我想将它组合成另一种名为Card的类型。//types.jstypeSuit=|"Diamonds"|"Clubs"|"Hearts"|"Spades";typeCard={...suit:Suit,...}与其直接在suit.js中对Suit字符串进行硬编码,不如根据JavaScript原语(数组)动态生成Suit类型?说...//constants.jsconstSUITS=['Diamonds','Clubs','Hearts','Spades'];通过这种方式,西装只需定义一次,并且可以在JavaScript结构中定义,该结构将在应用程序的其他部分中

javascript - 在 React ComponentDidMount 中访问 this.props

我是React新手,我被困在某个项目上。问题是我在从父组件接收到的this.props中有一个api_url。在这个子组件中,我想使用api_url来使用JSON获取一些数据。在我的父组件中:Repositoriesapi_url={this.state.objs.repos_url}在子组件中,我想要这样的东西:componentDidMount(){$.getJSON(this.props.api_url,function(json){for(vari=0;i所以我需要的是$.getJSON的url部分对应的api_url。有没有办法在componentDidMount中访问thi

javascript - Angular 2 : Type 'Subscription' is not assignable to type

我创建了一个非常小的应用程序来从json文件中获取国家并将其绑定(bind)到下拉列表。countries.jsonexportclassCountry{id:number;name:string;}factory.service.tsimport{Injectable}from'@angular/core';import{Http,Response}from'@angular/http';import{Observable}from'rxjs/Observable';import{Country}from'./shared/country';@Injectable()exportcl

javascript - "Resource interpreted as script but transferred with MIME type text/html."

很抱歉,如果这实际上是重复的,但我还没有设法找到我的问题的答案。我使用jQuery的$.getScript加载脚本。但它会导致以下错误:ResourceinterpretedasscriptbuttransferredwithMIMEtypetext/html.该问题仅在MacOS下的Safari中出现如果查看从服务器收到的header,它们包含Content-Type:application/x-javascript,所以我真的不明白问题出在哪里。 最佳答案 Resourceinterpretedasscriptbuttransf

javascript - React 16.3 中从 Prop 更新 Canvas 的正确生命周期方法是什么?

我有一个Canvas组件,大致如下所示:classCanvasextendsReact.Component{saveRef=node=>{this._canvas=node;}shouldComponentUpdate(){/*Iwillneverre-renderthiscomponent*/returnfalse;}componentWillReceiveProps(nextProps){/*HereIdomanipulationswiththis._ctx,whennewpropscome*/}render(){return();}componentDidMount(){this

javascript - 将数组传递给 Laravel View 并将该数组用作 VueJS prop

我有一个数组变量$screenshots,我正试图将其传递给我的LaravelView。通常,我会使用@foreach并循环遍历数组,但我想通过将整个数组定义为Prop来将其传递给Vue组件。我想这样做是为了循环遍历组件中的数组。我收到htmlentities()expectsparameter1tobestring,arraygiven错误。使用VueJS和Laravel执行此操作的正确方法是什么?这是我的Blade模板:@section('content')@endsection这是我的自定义组件(不同的文件):exportdefault{template:'#edit-ticke