四、React props属性

在comment文件夹下新建Comment.js

Comment.js

'use strict'

import React from 'react';

class Comment extends React.Component{
    render(){
        return (
            <div className="comment">
                <div className="content">
                    <span className="author">{this.props.author}</span>
                    <div className="metadata">
                        <span className="date">{this.props.date}</span>
                    </div>
                    <div className="text">{this.props.children}</div>
                </div>
            </div>
        )
    }
}

export {Comment as default}

使用 export 导出 Comment

 

在CommentList.js中引入Comment

import Comment from './Comment';
<Comment author="[author值]" date="[date值]">[children值]</Comment>

刷新页面

 

posted @ 2018-01-23 11:14  journeyIT  阅读(16)  评论(0编辑  收藏  举报