katex公式渲染的使用

3,199 阅读1分钟

katex介绍

  1. 将公式渲染成html标签
  2. 使用方法
    1.node 使用
    2.npm使用
    npm install katex
    import katex from 'katex'
    katex.renderToString(xx,dom)
    katex.render(xx,dom,options?:{
        throwOnError: false
    })

使用过程中出现的问题

公式渲染不出来

  • 定位为处理成的图片地址一样导致一直从缓存中取图片

解决方法

    document.querySelectorAll('img').forEach(item => {
        item.onerror = () => {
            item.srcElement.src = item.srcElement.getAttribute('src') + '?id=' + new Date().getTime()
        }
    })