在React中如何使用复合组件中的方法?
来源:互联网 发布:奇点.com mac软件 编辑:程序博客网 时间:2024/04/29 09:50
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script src="../js/react.js"></script> <script src="../js/react-dom.js"></script> <script src="../js/browser.min.js"></script></head><body><div id="example"></div><script type="text/babel"> var MainComponent=React.createClass({ handleOnClick:function () { console.log('这是复合组件的中的click方法'); }, render:function () { return <div> <h1>复合组件</h1> <ButtonComponent funName={this.handleOnClick}/> </div> } }) var ButtonComponent=React.createClass({ /*handleClick:function () {// console.log('this is a test'); this.props.funName(); },*/ render:function () { return <button onClick={this.props.funName}>click me</button> } }) ReactDOM.render( <MainComponent/>, document.getElementById('example') );</script></body></html>
上面是自己写的一个例子,可以使用props这个方法,访问到复合组件中定的方法。
0 0
- 在React中如何使用复合组件中的方法?
- React复合组件
- React-组件的复合
- React 复合组件
- React复合组件
- React-组件的复合
- React复合组件
- 在React中使用extends React.Component定义的组件
- 在react中如何使用tab组件-小白系列 es6
- 如何在react vr中使用中文
- 在Hive 中如何使用复合数据结构 maps,array,structs
- React学习笔记----如何在html页面中使用react
- react demo5 (自定义react复合组件)
- 在Servicemix中如何使用Quartz组件
- React(6)--组件的复合
- unity3d 如何让复合结构的数组在Inspector中显示其对象中的public属性
- 在react组件中监控滚动
- 如何在cocos2d-x中使用ECS(实体-组件-系统)架构方法开发一个游戏?
- [卡内基梅隆大学]10-725: Optimization Fall 2012 -Lecture 17: October 23 构造对偶函数
- Spring学习历程---WebApplicationContext初始化
- iOS学习资料
- VTK修炼之道6_仔细分析一个复杂程序
- poj2948 Martian Mining
- 在React中如何使用复合组件中的方法?
- 用户画像感性认识一
- easyui的combobox、combotree
- Android入门--四大组件---广播Broadcast--(4)
- unity5阴影
- 10. Regular Expression Matching
- 解决DEDECMS Call to undefined function dede_htmlspecialchars
- struts2文件上传与下载
- RecyclerView----高仿知乎的侧滑删除