【发布时间】:2017-01-04 23:11:16
【问题描述】:
基于此链接http://reactjs.cn/react/tips/expose-component-functions.html上的示例,我一直在尝试简化代码以更好地理解暴露的方法,所以我得到了以下内容,它不起作用,错误是“Uncaught TypeError: Cannot read property 'animate' of undefined",我真的不知道原因:
var Todo = React.createClass({
render: function() {
return <div></div>;
},
//this component will be accessed by the parent through the `ref` attribute
animate: function() {
console.log('Pretend is animating');
}
});
var Todos = React.createClass({
render: function() {
return (
<div>
<Todo ref='hello' />
{this.refs.hello.animate()}
</div>
);
}
});
ReactDOM.render(<Todos />, app);
【问题讨论】:
-
“不起作用”含糊不清。错误是什么?
-
您的问题已解决here。看看
-
错误是“Uncaught TypeError: Cannot read property 'animate' of undefined”
标签: javascript reactjs