【发布时间】:2018-05-14 13:43:14
【问题描述】:
对使用 Axios 渲染获取的数据有疑问。我能够将返回的数据记录到控制台,但是,它不会在屏幕上呈现。
我正在使用 NPM Bitly 模块:https://www.npmjs.com/package/bitly
const BitlyClient = require('bitly');
const bitly = BitlyClient('ACCESS TOKEN');
州
class Example extends Component {
constructor() {
super();
this.state = {
landing: 'https://www.google.com/',
newUrl: 'https://www.udacity.com/'
};
API 调用
componentDidMount() {
bitly.shorten(this.state.landing)
.then((response) => {
this.setState({newUrl: response.data.url })
console.log(response.data.url);
})
.catch(function(error) {
console.error(error);
});
}
这会将数据返回到控制台,但不会呈现到页面。
渲染到页面
<Component> {this.newUrl} </>
我错过了什么?
【问题讨论】: