- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如我已经阅读了在线和官方文档。订单是
构造函数-> ComponentWillMount -> 渲染-> ComponentDidMount 等。
class Navigation extends Component {
constructor(props) {
super(props);
console.log('constructor', this);
this.state = { items: [ ] };
}
componentDidMount() {
console.log('componentDidMount');
if ( toDisplay( ) ) {
api.bringCats()
.then( categories => {
const tot_cat = categories.map( cat => { return {name: cat.name, link: cat.link}; })
this.setState({items: tot_cat,})
})
}
}
render() {
console.log("render")
//some stuff
}
}
im expecting the the log to be in this order 1. constructor 2. ComponentDidMount 3. render
this
与
constructor
内部构造方法。我能够获得
items
的值(value)在
componentDidMount
中得到它的值(value)为什么会这样?及其以正确的顺序记录(构造函数->didmount->render)但是为什么我得到
items
的值甚至在调用
componentDidMount
之前.
<Navigation/>
内部组件
<Header/>
Header extends Component{
render(){
return (<div> <Navigation/> </div>);
}
}
最佳答案
我正在尝试一些东西,发现这工作正常。window.cnj = require('circular-json')
/* 我在起点第一行添加了这个,所以我可以在所有导入中访问它。 */window.props = JSON.parse(window.cnj.stringify(simple));
我可以访问window.props
来自开发工具及其按预期工作。sample
可以是字符串、数组、普通对象或圆形对象。
关于javascript - 哪个是第一个被调用的?构造函数或 componentDidMount 或 Render,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44892906/
我的父渲染中有下面的代码 { this.state.OSMData.map(function(item, index) { return })
你好,当我在 componentDidMount 方法之外的任何地方控制台记录我的组件的状态时,我发现我的状态充满了空数组,而这些空数组本应被构建。我正在从 JSON 文件和 componentDid
我有多个用于注册的模式,但遇到问题。我一共有三个 Action 。首先是注册按钮,然后激活第一个注册模式以注册 google 或 facebook,然后完成模式以获取提供者无法收集的其他信息,将与预先
我构建了一个 HOC 以在我的应用程序中的 protected 路由上使用。它接收应在路由上呈现的组件,检查用户是否经过身份验证,然后呈现该组件(如果是)。它可以工作,但它会导致组件多次挂载/卸载(与
class ProductsIndex extends Component { constructor (props){ super(props); console.log(
这是我在使用 React 时经常遇到的问题。 componentDidMount 方法保证在组件第一次渲染时被触发,因此它似乎是进行 DOM 测量(如高度和偏移量)的自然位置。然而,很多时候我在组件生
预期效果:在 componentDidMount () 中,我下载 s 并将其保存在变量 timeId 中。如果 timeId 为 true,则将 this.state.timeId 传递给 load
我有一个名为 DiscardPile 的组件,它在您的 props (props.cards) 中接收如下所示的对象数组: {key: 'key', 'type', suit: 'suit', lab
我正在尝试更新 componentdidmount 中的 fetch API 调用以匹配 React 中的输入,但我很难将输入传递到 URl 的模板文字中。有人可以解释一下吗? 代码- search(
我正在使用以下方式从保存的 session 中加载数据: componentDidMount() { if (JSON.parse(localStorage.getItem('savedDat
我在这里面临并提出问题,我想要第二个意见。当我的应用程序的第一页呈现时,出于安全原因我想清除我的状态,因此在我的布局类组件中我编写: componentDidMount() { this.pr
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在调用 ajax 请求 this.props.getPostListData(this.props.lang) 并出现错误。然后我发现它是 componentDidMount 的罪魁祸首。 我的
如何修复或禁用 ESLint 以忽略 [eslint] Expected an assignment or function call and instead saw an expression. (
我正在使用连接到 API 的 redux 和 sagas 开发一个 React 应用。 有一个表单组件有两个下拉字段:一个 Program 和一个 Contact 字段。该表单设计的工作方式是,当用户
我们有一个连接到 redux 存储的组件,它具有以下 componentDidMount 定义: async componentDidMount() { const page = await fe
我有一个 Header 组件,假设在用户登录的情况下呈现他的子组件。它通过 session 存储识别条件。我试图通过控制渲染componentDidMount: renderUserHeader =
这是我第一次在这里发帖,所以我很乐意接受对我发帖方式和帖子本身的评论。我学习编程才 8 周,所以可能有很多错误。 在这种情况下,我特别需要以下代码方面的帮助。 // import React, { C
我注意到 componentDidMount 有时不会按顺序触发。 componentDidMount(){ function1(); function2(); function3(); } 我
我有一个问题: 我在 componentDidMount() 中编写了 4 个函数,但我注意到编写这些函数的顺序不受尊重。 componentDidMount() { this.checkPe
我是一名优秀的程序员,十分优秀!