【问题标题】:how to use html in a material-ui Snackbar message如何在 material-ui Snackbar 消息中使用 html
【发布时间】:2019-06-20 09:17:37
【问题描述】:

我正在我的应用程序中尝试(反应)material-ui。这类似于文档中的示例:

function MySnackbarContentWrapper(props) {
    const classes = useStyles1();
    const { className, message, variant, ...other } = props;
    const Icon = variantIcon[variant];

    return (
        <SnackbarContent
            className={clsx(classes[variant], className)}
            aria-describedby="client-snackbar"
            message={
                <span id="client-snackbar" className={classes.message}>
                    <Icon className={clsx(classes.icon, classes.iconVariant)} />
                    {message}
                </span>
            }
            action={[
                <IconButton key="close" aria-label="Close" color="inherit" onClick={props.close}>
                    <CloseIcon className={classes.icon} />
                </IconButton>,
            ]}
            {...other}
        />
    );
}

现在,如果我的消息文本是:&lt;em&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;/em&gt;,它只会显示为:&lt;em&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;/em&gt;,而不是:Hello

有人可以帮助我实现这一目标吗?

当我过去使用 angularjs 时,我现在继续使用它,我将文本包裹在一个:ng-bind-html="alert.msg | unsafe" 中。现在,我现在不知道如何在 material-ui 中做到这一点。

非常感谢和再见...

【问题讨论】:

标签: reactjs material-ui


【解决方案1】:

您可以将消息作为“Hello”之类的文本传递,并为跨度提供带有 css 的斜体和粗体样式

.spanClass{
  font-style: italic;
  font-weight: 600;
}

【讨论】:

    猜你喜欢
    • 2020-10-08
    • 2023-03-17
    • 1970-01-01
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 2021-02-20
    • 2021-08-11
    相关资源
    最近更新 更多