我需要通过 module.export 从 axios 响应中读取数据。这是我的数据: http://localhost:8001
{
"name":"Nama Nih",
"desc":"Sekolah Terpadu Al-Qudwah - Yayasan Islam Qudwatul Ummah",
"prefix":"alqudwah",
"footerText":"Yayasan Islam Qudwatul Ummah | All Rights Reserved 2020",
"logoText":"Al-Qudwah",
"needLogin":false
}
我使用以下代码从 axios 调用数据: brand.js
var axios = require('axios');
module.exports = axios.get('http://localhost:8001', {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}})
.then(function (response) {
return response.data;
})
.catch(function (error) {
console.log(error);
})
.then(function () {
});
但是当我读取响应数据时,它并不像预期的那样。我尝试像这样控制台日志返回值:
这是我的代码,我在其中 console.log 响应。
import React, { PureComponent } from 'react';
import brand from 'ba-api/brand';
import { Helmet } from 'react-helmet';
class Dashboard extends PureComponent {
render() {
console.log(brand);
const title = brand.name + ' - Dashboard';
const description = brand.desc;
const { classes } = this.props;
return (
<div>
<Helmet>
<title>{title}</title>
<meta name="description" content={description} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
</Helmet>
</div>
);
}
}
Dashboard.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(Dashboard);
如何读取这些数据?