【问题标题】:Badge implementation with react and material-ui使用 react 和 material-ui 实​​现徽章
【发布时间】:2021-11-17 02:50:29
【问题描述】:

我试图在组件附有注释时显示徽章图标。我尝试了三种方法,得到了相同的结果,但我觉得很奇怪。哪一种是实现这一点的最佳方法?或者有没有其他方法

首先 从“@material-ui/core/Badge”导入徽章;

function NotesBadge({ hasNotes }) {
    
    return (
        <Badge
            anchorOrigin={{
                vertical: 'top',
                horizontal: 'right',}}
            variant="dot"
            color="primary"
            invisible={hasNotes}>
        </Badge>
    );
}

export default NotesBadge;

import Badge from '@material-ui/core/Badge';

function NotesBadge({ hasNotes }) {
    
    return (
        <Badge
            anchorOrigin={{
                vertical: 'top',
                horizontal: 'right',}}
            variant="dot"
            color="primary"
            invisible={!hasNotes}>
        </Badge>
    );
}

export default NotesBadge;

第三

import Badge from '@material-ui/core/Badge';

function NotesBadge({ hasNotes }) {
    if(hasNotes){
    return (
        <Badge
            anchorOrigin={{
                vertical: 'top',
                horizontal: 'right',}}
            variant="dot"
            color="primary"
            invisible={false}>
        </Badge>
    );
}
}
export default NotesBadge;

【问题讨论】:

    标签: javascript html css reactjs material-ui


    【解决方案1】:

    第二种方法是可行的方法,因为当hasNotes 为假时,Badge 必须是不可见的,因此得名。

    【讨论】:

      猜你喜欢
      • 2020-02-06
      • 2011-04-16
      • 2019-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 2021-11-20
      相关资源
      最近更新 更多