1.安装依赖 npm install --save mathlive
2.代码
<template>
<div>
<math-field ref="formula" virtual-keyboard-mode="manual" @change="jpChange"></math-field>
</div>
</template>
<script>
import { MathfieldElement } from "mathlive";
export default {
name: 'formula',
data() {
return {
mf: null,
};
},
model: {
prop: "value",
event: "change"
},
props: {
value: {
type: String,
default: () => ""
},
},
watch: {
value: {
immediate: true,
handler(val) {
if (this.mf && val) this.mfSetValue()
}
}
},
mounted() {
this.mf = this.$refs.formula
this.value && this.mfSetValue()
},
methods: {
mfSetValue() {
this.mf.setValue(this.value)
},
jpChange(e) {
this.$emit("change", e.target.value);
}
}
};
</script>