我有一个从 unix 时间戳计算日期的函数
_getTime(time) {
var dateTime = new Date(time*1000);
console.log(dateTime);
return dateTime
},
Run Code Online (Sandbox Code Playgroud)
该函数用于此
render: function() {
return (
{this.state.daily.map(day => {
return (
<div key={day.time} className="key col-md-12">
<div className="col-md-3">{this._getTime(day.time)}</div>
</div>
);
);
},
Run Code Online (Sandbox Code Playgroud)
这将返回Invariant Violation: Objects are not valid as a React child (found: Thu Oct 20 2016 00:00:00 GMT+0200 (CEST)). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render …
我需要一些帮助在我的反应应用程序中使用Axios.我将它与地理位置结合使用以获取用户位置并在与Axios的api调用中使用它.
我的代码是:
componentDidMount() {
if (navigator.geolocation){
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var th = this;
this.serverRequest =
axios.get(`https://api.darksky.net/forecast/APIKEY/`+latitude+`,`+longitude+`?units=auto`)
.then(result => {
th.setState({
daily: result.data.daily.data,
loading: false,
error: null
});
})
.catch(err => {
// Something went wrong. Save the error in state and re-render.
this.setState({
loading: false,
error: err
});
});
};
function error() {
console.log( 'geolocation error' )
};
navigator.geolocation.getCurrentPosition(success, error);
}
}
Run Code Online (Sandbox Code Playgroud)
但我最终得到了错误 Uncaught TypeError: Cannot set property 'serverRequest' of undefined
我正在努力改变CardMedia内部图像的高度
我用以下方式设置样式
const style = {
height: 32,
};
Run Code Online (Sandbox Code Playgroud)
并在其中使用
<CardMedia
overlay={<CardTitle title="Title"/>}
mediaStyle={style}>
<img src="imgUrl" />
</CardMedia>
Run Code Online (Sandbox Code Playgroud)
但是图像的高度保持不变。唯一发生的是带有标题的叠加层移到顶部。我已经尝试了所有CardMedia属性,但还没有成功