vue 中显示带有 latex 数学语法的 html 内容的方案

2021-01-28 23:10:23 +08:00
 zxCoder

查了好多也没找到有效的做法

后台获取到的是一个字符串,是 html 格式,然后里面带有一些 latex 公式,例如

"Then, Mikaela will count and give you the number of pairs of vertices $$$(s, t)$$$ where $$$s \in S$$$ and $$$t \in T$$$ such that the simple path from $$$s$$$ to $$$t$$$ contains $$$v$$$.</p><p>Mikaela the Goddess is busy and will be available to answer at most $$$11\,111$$$ questions.</p><p>This is your only chance. Your task is to determine the tree and report its edges.</p>"

用 vue 的 v-html 可以直接展示 html,但是其中的 latex 公式不知道要怎么办,网上找的几种 mathjax 的方法都不好用而且很麻烦

835 次点击
所在节点    问与答
2 条回复
iConnect
2021-01-29 00:02:12 +08:00
你试下 $nextTick 方法,一定要让数据加载完之后再让 mathjax 渲染 LaTeX,mathjax 提前渲染了这时 v-html 数据还没加载完就无效果了
XiaoxiaoPu
2021-01-29 00:21:39 +08:00
找到一个应该可以用的 mathjax vue 封装 github.com/justforuse/vue-mathjax

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/749376

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX