jjzjj

COMPONENT

全部标签

javascript - react : 'this.state' is undefined inside a component function

我在组件内的函数中访问this.state时遇到问题。我已经找到了this关于SO的问题并将建议的代码添加到我的构造函数中:classGameextendsReact.Component{constructor(props){super(props);...this.state={uid:'',currentTable:'',currentRound:10,deck:sortedDeck};this.dealNewHand=this.dealNewHand.bind(this);this.getCardsForRound=this.getCardsForRound.bind(this)

javascript - 从 Vue.js 中的父组件执行子方法

目前,我有一个Vue.js组件,其中包含其他组件的列表。我知道使用vue的常见方式是将数据传递给child,并从child向parent发送事件。但是,在这种情况下,我想在单击父中的按钮时在子组件中执行一个方法。哪种方法最好? 最佳答案 一个建议的方法是使用globaleventhub.这允许有权访问集线器的任何组件之间进行通信。这是一个示例,展示了如何使用事件中心来触发子组件上的方法。vareventHub=newVue();Vue.component('child-component',{template:"The'clicke

javascript - 我可以在未注册的组件上构建 Vue.js 失败吗?

考虑以下组件模板......其中Unknown可能是全局注册的组件。在运行时,我会遇到这个信息性错误:[Vuewarn]:Unknowncustomelement:-didyouregisterthecomponentcorrectly?Forrecursivecomponents,makesuretoprovidethe"name"option.[...]但是,对于我的用例,我想强制在构建时不会发生此类事件。目前,vue-cli-servicebuild在这种情况下执行成功构建,然后在运行时显示错误(此时无用)。我很好奇是否有一种方法可以内省(introspection)地捕获这个潜

javascript - 如何使用 KARMA 对 React JSX ES6 代码进行单元测试?

我用ES6编写了我的React应用程序。现在我也想用ES6编写我的测试。所以这里的挑战是配置karma。与谷歌一起,我用karma.config.js走到了这一步(我省略了配置文件中相同的部分!):...files:['../node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js','../app/**/*.jsx','../test/**/*.jsx'],preprocessors:{'app/**/*.jsx':['react-jsx','babel'],'test/**/*

javascript - 如何让 React HOC - 高阶组件协同工作?

我有一个像这样的小演示组件:functionMyList({data,uppercaseMe,lowercaseMe}){return{data.map(item=>{item}-uppercaseMe(item)}>Uppercaseme!lowercaseMe(item)}>Lowercaseme!)};}然后我想用三个HOC来装饰MyList:constWithData=(Component)=>{returnclassextendsReact.Component{constructor(props){super(props);this.state={data:['one','t

javascript - Angular 2 : Validate child component form fields from the parent component

问题陈述:父组件有标签和一些里面的标签,子组件也有一些标签,父组件有一个我们正在验证提交表单时的表单字段。如何验证子组件来自父组件的字段submit表格?要求:如果父组件的表单包含带有input的子组件模板中的组件,然后是这些input如果从父组件提交,组件应该在点击时验证。调查结果:SO中有很多帖子有相同的问题陈述,但没有找到任何合适的解决方案。以下所有帖子都验证了整个表单,但我的要求是验证子组件中的每个字段。Angular2validationtogetherwiththechildcomponentAllowtemplate-drivenforminputsacrossacomp

javascript - 如何从 Vue.js 中的变量名加载组件?

我想从我的vue.js应用程序中的动态变量名加载一个组件。我注册了以下组件:Goal:{{data.text}}而不是像这样加载我想从一个变量名加载,像这样:当然,在这种情况下,mytemplate.type等于“目标” 最佳答案 使用dynamiccomponent像这样: 关于javascript-如何从Vue.js中的变量名加载组件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questi

javascript - React.js 中的混合和复制方法

越来越多地了解React.js的魅力,我开始使用Mixins更多的。我注意到的一件事是,我的mixin和我的组件都可以有一个componentDidMount方法——这两个函数都会被调用,所以在组件中定义它不会覆盖混合中的那个,反之亦然。这是一个例子:varMyMixin={componentDidMount:function(){//Dosomethingwhencomponentismountedconsole.log("Mixinfnran");}};varComponent=React.createClass({mixins:[MyMixin],componentDidMoun

javascript - Angular 6 @Viewchild 不适用于延迟加载

这是我的代码,提示无法读取未定义的属性标题。父组件import{Child}from'./child.component';@Component({selector:'parent',})exportclassParentComponetimplementsOnInit,AfterViewInit{constructor(){}@ViewChild(Child)child:Child;ngAfterViewInit(){console.log("checkdata",this.child.title)}}子组件是。@Component({selector:'child',})expor

javascript - 错误 : Uncaught (in promise): Error: Cannot match any routes RC4 Child Routes

在Angular应用程序中实现子路由的演示应用程序Angular2应用程序显示错误Error:Uncaught(inpromise):Error:Cannotmatchanyroutes:'movie-home'zone.js:461UnhandledPromiserejection:Cannotmatchanyroutes:'movie-home';Zone:angular;Task:Promise.then;Value:Error:Cannotmatchanyroutes:'movie-home'(…)如果我不从文件movie.routes.ts添加这些代码行,应用程序工作正常{p