【发布时间】:2018-06-30 16:41:41
【问题描述】:
我使用的是 preact(react 的轻量级版本),但语法几乎相同。从承诺结果设置状态后,我在显示已验证时遇到问题。这是我的容器组件:
import { h, Component } from "preact";
import { VerifierService } from "services/verifierService";
var CONFIG = require("Config");
//import * as styles from './profile.css';
interface PassportProps { token?: string; path?: string }
interface PassportState { appId?: string; verified?: boolean }
export default class Passport extends Component<PassportProps, PassportState> {
constructor(props) {
super(props);
this.state = { appId: CONFIG.Settings.AppId };
}
async componentDidMount() {
console.log("cdm: " + this.props.token);
if (this.props.token != undefined) {
await VerifierService.post({ token: this.props.token })
.then(data => {
this.setState({ verified: data.result });
console.log(JSON.stringify(data, null, 4));
})
.catch(error => console.log(error));
}
}
render() {
return <div>Test: {this.state.verified}</div>;
}
}
我可以在 promise 结果中看到 console.log 为 true,但我无法在视图中显示它。
【问题讨论】:
-
console.log中的数据是什么样的? -
"true" 作为布尔值
标签: javascript reactjs preact