【问题标题】:ReactJS: get mediumtext from MySQL and view formatted textReactJS:从 MySQL 获取 mediumtext 并查看格式化文本
【发布时间】:2019-12-08 16:18:47
【问题描述】:

我有一个非常具体的问题,所以: 我的 MySQL 数据库中有一个中等文本。例如(带断线):

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

我想现在使用 get HTTP 方法获取此文本,并在我的站点显示中,所有Lorem Ipsum粗体 显示。

有什么可以得到的吗? 我将 ReactJS 与 Redux + Redux-Saga 一起使用

或者也许IN数据库,我可以在html中插入中等文本,但是如何在前端显示呢?

【问题讨论】:

    标签: mysql reactjs


    【解决方案1】:

    存储 html 并使用 dangerouslySetInnerHTML 来呈现它。您可以阅读this post 更深入地了解它。

    const text = '<strong>Lorem ipsum</strong> dolor sit';
    
    const App = ({html}) => (
      <div dangerouslySetInnerHTML={{ __html: html }} />
    )
    
    ReactDOM.render(<App html={text} />, document.getElementById('root'));
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
    <div id="root"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 2014-06-14
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多