【发布时间】:2021-06-06 20:49:54
【问题描述】:
我真的很难过,现在已经尝试了一个星期了尝试了各种各样的东西,但无法让它发挥作用。我真的在互联网上找不到任何东西,所以请帮助我,即使这可能是一个特定的问题
我想要实现的目标: 我想用 Pending 来“补偿” text1 或 text2 的空行。这些行有时是空的,有时是文本。它们在不同组件中的上传时发生变化。 因此,如果 text1 为空,我想将 1 添加到 this.state.count
我为什么要打印一本手册,格式非常重要。通常周围有更多代码,但我将其删除以使其更容易理解
import React, { Component } from "react";
import axios from "axios";
class BspComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
karte: [],
text1: "",
text2: "",
count: 0,
};
}
componentDidMount() {
axios
.get("http://test.com")
.then((response) => {
this.setState({
karte: response.data,
text1: response.data.z1,
text2: response.data.z2,
});
})
.catch((error) => {
console.log(error);
});
}
render() {
return (
<div>
<div
className="atDistance" /** This Componant should get a padding is text1 is empty */
style={{
paddingTop: `${this.state.count}cm`,
}}
>
BLA BLA
</div>
<div className="wrapper" /** text1 and 2 change on an Upload in a difrent Component */>
<p>{this.state.text1}</p>
<p>{this.state.text2}</p>
</div>
<div
className="atDistance" /** This Componant should get a padding is text1 is empty */
style={{
paddingTop: `${this.state.count}cm`,
}}
>
BLA BLA
</div>
</div>
);
}
}
export default BspComponent;
我尝试了什么:
-
检查渲染 -> 没有工作,因为我无法达到状态 + 在状态渲染之前有填充组件
-
签入 ComponentDidMount ->不知道为什么没有工作
-
使用 onChange -> 无法调用该函数时出现错误,因为我陷入了无限循环
如果您有一个很好的想法来处理这个问题,那就太酷了。我哪儿也去不了
【问题讨论】: