<!-- <textarea id="input" rows="15" cols="10"> % % 请输入您想要的公式 % \LaTeX </textarea> --> <el-inputclass="input"type="textarea":rows="10":columns="10"placeholder="请输入数学公式"v-model="textArea" clearable @input="convert()"> </el-input> <br /> <divclass="left"> <!-- <input type="checkbox" id="display" checked onchange="convert()"> <label for="display">Display style</label> --> <el-checkboxv-model="checked">显示公式样式</el-checkbox> </div> <divclass="right"> <!-- <input type="button" value="Render TeX" id="render" onclick="convert()" /> --> <el-buttontype="success" @click="copy()">复制$\LaTeX$公式</el-button> <el-buttontype="success" @click="convert()">强制转换</el-button> </div> <brclear="all" /> <!-- <div id="output" v-if="this.textArea === '%请输入数学公式(本句为注释)\n'" style="opacity: 0.5;zoom: 2;">$$\LaTeX$$</div> --> <divid="output"></div> </div> <script> new Vue({ el: '#app', data: { textArea: '', checked: true }, methods: { convert: function () { // // Get the TeX input // // var input = document.getElementById("input").value.trim(); var input = this.textArea; if (this.textArea === ''){ input = '\\LaTeX' } // // Clear the old output // output = document.getElementById('output'); output.innerHTML = ''; // // Reset the tex labels (and automatic equation numbers, though there aren't any here). // Get the conversion options (metrics and display settings) // Convert the input to CommonHTML output and use a promise to wait for it to be ready // (in case an extension needs to be loaded dynamically). // MathJax.texReset(); var options = MathJax.getMetricsFor(output); options.display = this.checked; MathJax.tex2chtmlPromise(input, options).then(function (node) { // // The promise returns the typeset node, which we add to the output // Then update the document to include the adjusted CSS for the // content of the new equation. // output.appendChild(node); MathJax.startup.document.clear(); MathJax.startup.document.updateDocument(); }).catch(function (err) { // // If there was an error, put the message into the output instead // output.appendChild(document.createElement('pre')).appendChild(document.createTextNode(err.message)); }).then(function () { // // Error or not, re-enable the display and render buttons // // button.disabled = display.disabled = false; }); }, copy: function () { var input = this.textArea; var oInput = document.createElement('input'); oInput.value = input; oInput.select(); document.execCommand("Copy"); this.copySuccess(); }, copySuccess: function () { this.$message({ message: '复制成功', type: 'success' }) }, copyFailure: function () { this.$message.error('复制失败'); } } }) </script>