"Why is there a need to refresh the page in Vue.js 3 for MathJax to work on initial display, but it doesn't work in step

My goal is to show the same expressions in two steps on a single page, one after the other. I have included links to images here: enter image description here, enter image description here. Along with this, there should be a button that increments a counter (etape).

While developing, I noticed that the display updates in real-time but some expressions are only interpreted after refreshing the browser page. Additionally, in the second step, mathematical expressions are not being interpreted properly. This issue has left me perplexed.

In my main.js file:

import { createApp } from 'vue'
import App from './App.vue'
import VueMathjax from 'vue-mathjax-next';

createApp(App).use(VueMathjax).mount('#app')

In my App.vue file:

<template>
    <div id="app">
        <h1>Étape = {{ etape }}</h1>
        <h2> Requires page refresh even on initial display </h2>
        <div v-if="etape >= 0">
            <ul>
                <li>
                    <h3>(E 1) </h3> $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}. $$
                </li>
                <li>
                    <h3>(E 2) </h3> \( f(x) = x^2 + 2 x=2 \)
                </li>
                <li>
                    <h3>(E 3) </h3> \( P_A(B) = \frac{P(A \cap B)}{ P(A)} \)
                </li>
            </ul>
            <h2> But the following two scriptures are not interpreted </h2>
            <ul>
                <li>
                    <h3>(E 4) </h3> $ f(x) = x^2 + 2 \quad \mathrm { if } \quad x=2 $
                </li>
                <li>
                    <h3>(E 5) </h3> $ P_A(B) = \frac{P(A \cap B)}{ P(A)} $
                </li>
            </ul>
            <br />
            <button @click="etape++"> Press Next Step</button>
        </div>
        <div v-if="etape >= 1">
            <hr>
            <h2> Second Step: Étape = {{ etape }} </h2>
            <ul>
                <li>
                    <h3>(E 1) </h3> $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}. $$
                </li>
                <li>
                    <h3>(E 2) </h3> \( f(x) = x^2 + 2 x=2 \)
                </li>
                <li>
                    <h3>(E 3) </h3> \( P_A(B) = \frac{P(A \cap B)}{ P(A)} \)
                </li>
            </ul>
            <ul>
                <li>
                    <h3>(E 4) </h3> $ f(x) = x^2 + 2 \quad \mathrm { if } \quad x=2 $
                </li>
                <li>
                    <h3>(E 5) </h3> $ P_A(B) = \frac{P(A \cap B)}{ P(A)} $
                </li>
            </ul>
        </div>
    </div>

</template>

<script>
export default {
    components: {},
    data() {
        return {
            etape: 0,
        }
    }
};

</script>
<style>
</style>

I spent several fruitless hours trying to debug this issue and have summarized it briefly here to pinpoint the problem.

Answer №1

I came across a solution:

Apps.vue :

<template>
  <div id="app">
    <h1>Step = {{ step }}</h1>
    <h2>
      With vscode, changing src requires page refresh even on initial display
    </h2>
    <div v-if="step >= 0">
      <ul>
        <li>(E 1) <vue-mathjax :formula="root" /></li>
      </ul>
      <br />
      <button @click="step++">Press Next Step</button>
    </div>
    <div v-if="step >= 1">
      <hr />
      <h2>Second Step: Step = {{ step }}</h2>

      <textarea v-model="probability" />
      <br />
      with input: <vue-mathjax :formula="probability" /> <br />
      without input:
      <vue-mathjax :formula="simpleFraction" />
    </div>
  </div>
</template>
<script>
export default {
  components: {},
  data() {
    return {
      step: 0,
      root: "$ x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}. $ ",
      probability: "$ P_A(B) = \\frac{P(A \\cap B)}{ P(A)} $",
      simpleFraction: "$ \\frac{1}{2} $",
    };
  },
};
</script>
<style>
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the correct method for launching a modal window in wagtail-admin?

I am currently working on enhancing my wagtail-admin interface, but I have hit a roadblock when trying to open a modal window. While I could create a div with a close button, I believe there must be a more appropriate method for achieving this. It seems th ...

The function element.checked = true/false in Vanilla Javascript seems to be malfunctioning

Here is the HTML code I am working with: <ul class="nav md-pills pills-default flex-column" role="tablist"> <li class="nav-item"> <input type="radio" name="q01" value="1" hidden checked> <a class="nav-link choice01 ...

What is the best way to manage a blank input?

How can I manage an empty input field? I am currently working on my first React component and I am struggling with the logic to handle or detect when an input is empty. The goal is to change the input's border color based on its content: - If the i ...

Whispering form using onblur and onfocus

Seeking assistance with echoing a form that includes multiple input fields. Specifically, I am attempting to utilize onblur and onfocus (refer to the conditions outlined in the code). However, I am encountering an issue where the Javascript function does ...

Steps for converting a tsx file into a js file in React

Currently, I am in the process of a React Project and have numerous tsx files that I aim to convert for utilization as JavaScript within my project. What would be the best approach to achieve this task? ...

Simultaneous malfunction of two ajax forms

I have a dilemma with two boxes: one is called "min amount" and the other is called "max amount." Currently, if I input 100 in the max amount box, it will display products that are priced at less than $100. However, when I input an amount like $50 in the m ...

You can update a JavaScript string by adding values using the '+=' operator

I have the following function: function generateJSONstringforuncheckedfilters(){ jsonstring = ''; jsonstring = "["; $('body').on('click', 'input', function(){ jsonstring += "[{'OrderGUID&apo ...

Performing tasks when a component is fully loaded in Vue.js Router

I am currently working on a project involving a single-page application built with Vue.js and its official router. For this project, I have set up a menu and a separate component (.vue file) for each section that is loaded using the router. Inside every c ...

Troubleshooting problem with cookies in express-session

I've been working on an app with express.js and vue 3, incorporating session-based authentication. While everything functions perfectly locally, I've encountered issues when trying to deploy to production. Here's a snippet of the code where ...

Expanding the functionality of express.Router

Can someone help me with how to extend the functionality of express.Router? I attempted the following: class Test extends express.Router() { }; However, I encountered an error when trying this in Express. Does anyone have a solution for this issue? ...

Enable the use of multiple decimal separators in a ReactJS application

I am currently developing a small project that involves using a POST request, which requires multiple fields with 2 float values. My backend system expects the decimal separator to be a ".", but my target audience is primarily French and they ar ...

Guide on incorporating Foundation breakpoint util into Vue-CLI project

I'm facing an issue while trying to incorporate Foundation breakpoint util into Vue-CLI for it to be accessible in every component. The error message I am getting is as follows: SassError: (small: 0, medium: 640px, large: 1024px, xlarge: 1200px, xxlar ...

Executing a function when a specific element is triggered within an ng-repeat in AngularJS

Hey there, I've been grappling with changing the limitTo filter on a specific list, but I'm encountering an issue: whenever I trigger the filter change, it applies to all ng-repeated categories. The function within my main controller is as foll ...

Customized validation message in Angular Formly with live data

I'm currently working with angular-formly and attempting to create a validation that checks if the user input falls within a dynamically set range of two numbers. I thought the simplest way to achieve this was by using a few variables, and while the v ...

Add more key value pairs to another <div> element

My setup involves radio buttons attached to div elements. When a div is clicked, the information displayed on the widget updates to show the data associated with that div. I am using the Yahoo API to fetch the data in JSON format. The correct data is being ...

Is there a way to distribute my World instance among several step definition files in CucumberJS?

Currently, I am working on implementing a CucumberJS scenario that involves using multiple steps spread out across two separate step definition files. In this setup, the first step establishes certain variables in the World object which need to be accessed ...

I keep encountering an issue every time I try to use ng-repeat in my

I am using NG-repeat to display results. The information is retrieved from an array through an API call using $http.post. One of the items in the results is a 'Thumbnail'. A snippet of the result looks like this: "Thumbnail":"http ...

Creating a scheduled redirect button using JavaScript and another button to cancel it

I'm facing an issue with my code. When the first button is clicked, it redirects the user to a different URL after 10 seconds. However, I'm struggling to make the second button cancel the redirect if pressed before the 10 seconds are up. Despite ...

What is the best way to incorporate this custom file upload button, created with vanilla JavaScript, into a React application?

Hey there! I have successfully implemented a custom file upload button using HTML, CSS, and JS. Now, I want to recreate the same design in React. Can someone guide me on how to achieve this in React? HTML Code: <br> <!-- actual upload which is h ...

What is the best way to transform a current callback API into promises?

Exploring the transition to working with promises poses a challenge when dealing with callback APIs structured as follows: ###1. Handling DOM load or other one-time event: window.onload; // set to callback ... window.onload = function() { }; ###2. Utili ...