【发布时间】:2018-08-26 20:43:18
【问题描述】:
我有一个看起来像这样的 ReactJS 组件:
import React from 'react';
class Circle extends React.Component {
constructor(props) {
super(props);
this.state = {
error: null,
isLoaded: false,
percent: null
};
}
componentDidMount() {
const url = "base url here" + this.props.endpoint;
fetch(url)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
percent: result.percent
});
},
(error) => {
this.setState({
isLoaded: true,
error: error
});
}
)
}
render() {
return (
<div className={"col-md-" + this.props.size + " progress-circles"} data-animate-on-scroll="on">
<div className="progress-circle" data-circle-percent={"" + this.state.percent + ""} data-circle-text="">
<h4>{this.props.title}</h4>
<svg className="progress-svg">
<circle r="80" cx="90" cy="90" fill="transparent" strokeDasharray="502.4" strokeDashoffset="0"></circle>
<circle className="bar" r="80" cx="90" cy="90" fill="transparent" strokeDasharray="502.4" strokeDashoffset="0"></circle>
</svg>
</div>
</div>
);
}
}
export default Circle;
到目前为止,这就像一个完美的魅力。唯一的问题是,有一个与该元素关联的动画填充进度圈,并且在我从componentDidMount 函数设置值后它不会发生。如果我通过父组件的道具设置值,动画确实会发生。我错过了什么吗?我是 React 的新手,所以它可能很简单。提前致谢!
【问题讨论】:
标签: javascript html reactjs animation