mysql - ReactJS:从 MySQL 获取 mediumtext 并查看格式化文本
问题描述
我有一个非常具体的问题,所以:我的 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 一起使用
或者可能在数据库中,我可以在 html中插入中等文本,但是如何在前端显示呢?
解决方案
存储 html 并用于dangerouslySetInnerHTML
渲染它。阅读这篇文章,您可以更深入地了解它。
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>
推荐阅读
- java - 当 post 请求在邮递员中完成时,它将所有值传递为 NULL
- node.js - JSON 服务器 - 使用 cronjob 更新数据库
- r - 第一页和其他页的标题
- c# - 创建一个随机数组并获取索引中的值以及输入值但获取的信息错误时的索引
- c++ - 将标记转换为 char* const* 时,使用 boost 标记字符串失败
- sql-server - 使用没有凭据提示的 Powershell 将数据加载到 SQL Server
- python - 带有 xpath 的继承字段不会出现在最终视图中 - Odoo 12
- python - 类应该包括可以在 y 中的所有有效标签
- javascript - 如何将 Excel 文件转换为文件超过 20 MB 的 Google 表格?
- javascript - JavaScript:setAttribute 有效,但 .style 无效