vue单页面引入MathJax(显示使用vue-MathJax)

it2025-10-23  14

安装vue-mathjax

npm install --save vue-mathjax

单页面引入js组件,vue-mathjax组件

import {VueMathjax} from 'vue-mathjax' export default { ... components: { 'vue-mathjax': VueMathjax, 'jsCdn': { render(_) { return _('script', { attrs: { type: 'text/javascript', src: this.cdn } }) }, props: { cdn: { type: String, required: true } } } }, ...

使用

<template> <div> <jsCdn cdn="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-AMS_HTML"/>//单页面引入了mathJax.js <vue-mathjax :formula="mathjax"></vue-mathjax> </div> </template> <script> <!-- You can also define globally --> import { VueMathjax } from 'vue-mathjax' export default { components: { 'vue-mathjax': VueMathjax, 'jsCdn': { render(_) { return _('script', { attrs: { type: 'text/javascript', src: this.cdn } }) }, props: { cdn: { type: String, required: true } } } }, name: 'mathjax', data () { return { mathjax: '$$\sum_{i=0}^N\int_{a}^{b}g(t,i)\text{d}t$$' } } } </script>
最新回复(0)