美文网首页前端node
reactive native 建立组件的三种方式

reactive native 建立组件的三种方式

作者: 雨滴小 | 来源:发表于2017-12-11 15:17 被阅读0次

以定义名为Hello的组件为例:

一:es6方式

a:从react 包中导入react和component

b:定义所需要的组件名,继承component,并指定render()方法,同时需要导出组件名

exp: class Hello extends React.Component { 

 render() { 

 return  }

}

导出方式:(有两种)

1:直接在定义的组件类前加export default

2:在组件的文件末尾添加export default 组件名

exp:  export default Hello;

二:es5方式

exp: var Hello =React.createClass({ 

 render() {   return }

})

导出组件:module.exports=Hello;

三:使用函数方式定义(没有状态,不能使用this方法)

exp:function Hello(Props){

 return

}

导出组件(和es5方式相同):module.exports=Hello;

相关文章

网友评论

    本文标题:reactive native 建立组件的三种方式

    本文链接:https://www.haomeiwen.com/subject/gywyixtx.html