jjzjj

component

全部标签

javascript - 如何对所有路由 Root 和 Child Routes 使用 angular 6 Route Auth Guards?

如何为所有路由Root和ChildRoutes使用angular6RouteAuthGuards? 最佳答案 1)[创建守卫,文件名类似于auth.guard.ts]nggenerateguardauthimport{Injectable}from'@angular/core';import{CanActivate,ActivatedRouteSnapshot,RouterStateSnapshot}from'@angular/router';import{Observable}from'rxjs/Observable';impor

javascript - 如何测试在 componentDidMount 中设置 React Component 状态的异步调用

测试componentDidMount中的异步调用设置React组件状态的最佳方法是什么?对于上下文,我用于测试的库是Mocha、Chai、Enzyme和Sinon。这是一个示例代码:/**assumearecordlookslikethis:*{id:number,name:string,utility:number}*///asyncComponent.jsclassAsyncComponentextendsReact.Component{constructor(props){super(props);this.state={records:[]};}componentDidMou

javascript - 在 React 组件中进行重定向的适当生命周期阶段是什么?

这个问题在这里已经有了答案:Whatcomponentlifecycletousetodosomethingbeforerender()?(4个答案)关闭3年前。我想根据外部条件渲染一个组件,否则重定向到应用的其他地方。理想情况下,此重定向应在组件之前决定,但在某些情况下,我觉得我需要在组件中执行此操作。例如,在ReactRouter中,路由器可能看起来像这样:LoadingPage的逻辑/sudocode将是这样的:if(stillLoading){render}elseif(loggedIn){redirectToHome}else{redirectToLogin}这变得很复杂,因

javascript - 如何将 $scope 传递给 angularjs 1.5 组件/指令

我正在尝试在Angular1.5中使用新的.component()方法。目前我发现关于如何使用它的信息很少。Angular文档也没有真正提到它。我正在尝试将作用域或对象从作用域传递到.component以在组件的模板部分中使用,但我可以传递的唯一两个参数是$element和$attrs。我尝试通过html中的属性传递对象,但我得到的只是对象名称的字符串。我尝试过将其设置为以这些方式表示为变量my-attr="item.myVal"my-attr="{item.myVal}"my-attr="{{item.myVal}}"每次我仍然得到字符串文字而不是变量的值。如何将其设置为作为变量处理

javascript - react + 终极版 : Component does not update

尝试使用React+Redux,并且可能正在做一些明显愚蠢的事情,因为触发操作以通过网络获取数据的组件在获取数据时不会得到更新(重新呈现)。这是我的代码的相关部分:作为应用程序入口点的顶级index.js:importReactfrom'react';importReactDOMfrom'react-dom';import{Provider}from'react-redux';import{createStore,applyMiddleware}from'redux';import{Router,browserHistory}from'react-router';importredux

javascript - 以 Angular 4 在路由器导出外加载页面

我正在开发一个angular4应用程序,我想在router-outlet之外加载login.page.ts这是我的home.component.html文件路由配置constMAINMENU_ROUTES:Routes=[{path:'login',component:LoginComponent},{path:'',redirectTo:'home',pathMatch:'full'},{path:'home',component:HomeComponent,canActivate:[AuthGuard]}];有了这个,我可以在路由器内加载登录页面,但我想在进入路由器导出之前全屏加载

javascript - Angular 2 子应用、父/子、嵌套组件、嵌套路由器 socket 、设计/编码

我有一个Angular2应用程序。主屏幕(应用程序?)看起来像这样......当您单击顶部菜单routerLinks中的项目时,新组件将加载到主视图路由器socket中。其中一个链接加载了一个新的“管理”模块/组件,它有自己的路由和新的路由器导出......然后当您单击左侧导航栏中的routerLinks时,新的管理组件将加载到新的路由器socket中。但是……Angular2不允许超过1个路由器socket。因此,单击左侧导航栏中的任何routerLink只会替换整个初始路由器导出View。我看过一些关于使用“bootstrap”加载后续组件的SO帖子(较旧的,可能已弃用),但我无法

javascript - React - 动态导入组件

我有一个页面,它根据用户输入呈现不同的组件。目前,我已经对每个组件的导入进行了硬编码,如下所示:importReact,{Component}from'react'importComponent1from'./Component1'importComponent2from'./Component2'importComponent3from'./Component3'classMainextendsComponent{render(){varcomponents={'Component1':Component1,'Component2':Component2,'Component3':C

javascript - @types/styled-components 重复标识符 FormData

如果我在我的项目中添加@types/styled-components,我将在构建输出中出现一堆错误:ERRORin/Users/me/projects/react/node_modules/@types/react-native/globals.d.ts(36,15):TS2300:Duplicateidentifier'FormData'.ERRORin/Users/me/projects/react/node_modules/@types/react-native/globals.d.ts(81,5):TS2717:Subsequentpropertydeclarationsmu

javascript - 如何使用 es6 模板文字作为 Angular 组件输入

在我的Angular4应用程序中,我有一个接受字符串输入的组件:在某些情况下我需要在字符串中传递一个变量,例如:如果我可以使用es6templateliterals就好了(又名模板字符串或反引号字符串):但它不起作用:UncaughtError:Templateparseerrors:ParserError:UnexpectedtokenLexerError:Unexpectedcharacter[`]atcolumn1inexpression完成它的正确方法是什么? 最佳答案 ES6Templateliterals(Templat