Vue2Editor not displaying updated content following data retrieval from axios call

I've encountered an issue with my Vue component that uses Vue2Editor. Everything was working great until I tried to update the content using data from an async function.

To troubleshoot, I tested updating text in a simple div.

Here's a snippet of my async function code:

async getPost(id) {
   this.content = "Here works"; // Update both content
   const {data} = await pressRepository.getPost(id)
   document.getElementsByClassName("ql-editor")[0].focus();
   this.content = data.article; // Update just the div content
}

Success:

<div> {{content}}</div>

Issue:

<vue-editor v-model="content" :editorToolbar="customToolbar"></vue-editor>

[EDIT]

Fixed! by commenting out this line:

//document.getElementsByClassName("ql-editor")[0].focus();

Answer №1

Give this a shot.

async fetchPost(id) {
   this.message = "Success"; // Modify message
   const {data} = await postApi.fetchPost(id)
   document.getElementsByClassName("ql-editor")[0].focus();

   this.$nextTick(() => {
     this.message = data.article; // Update specific content
   })
}

Answer №2

Give this a try: this.$forceUpdate()

Additionally, here is a functional example:

<template>
  <div id="app">
    <vue-editor v-model="body"/>
    <button @click="update">Update</button>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  name: "App",
  components: {
    VueEditor
  },
  data() {
    return {
      body: `<b>Lost list↓↓↓</b>
    <ul>
       <li>a</li>
       <li>a</li>
       <li>a</li>
    </ul>
    <b>Lost list↑↑↑</b>`
    };
  },
  methods: {
    update() {
      this.body = 'Test texttttt ';
    }
  }
};
</script>

Answer №3

I successfully resolved the issue by uncommenting the code

    //document.getElementsByClassName("ql-editor")[0].focus();

Strange that it wasn't functioning properly with the async function, but the problem has been rectified.

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

The issue persists as AJAX data and text box data are not being saved simultaneously

I need assistance with an Ajax setup. I am trying to pass the screenwidth information along with a user input value from a text box to a PHP page. However, I am encountering issues as the only value being passed is from the textbox and the other one is sho ...

Guide on waiting for AWS assumeRole before proceeding with defining the module

I'm currently working on a module that needs to export functions and variables, but before it can do that, it must switch user roles. Here is the code snippet I've come up with. What I need is for the anonymous async function to execute first, an ...

Extracting data from a webpage's dynamic table using Python with Selenium and

I am planning to extract the data from the JavaScript tables found in the following link: import codecs import lxml.html as lh from lxml import etree import requests from selenium import webdriver import urllib2 from bs4 import BeautifulSoup URL = &apo ...

Ways to verify if a specific email and name are already present in MongoDB

I need to check if a selected user's email and name already exist in my MongoDB database. I want to ensure that both the email and name are unique, without any duplicates of these values. Although I have functional code for this task, I am curious if ...

Struggling with Getting My Animation to Function Correctly

I am trying to create a JQuery Animation that will move a div covering a text box up into the border when clicked. Despite multiple attempts, I can't seem to get the animation to work properly. Any suggestions? JavaScript function moveup(title,text ...

Problem with Angular: ng-show not constantly re-evaluating expression

Utilizing a variable named activeScope to manage the state and toggle between two forms. This variable updates its value when a tab is clicked, triggering changeScope. While the change in active states for the tab buttons registers correctly, the divs for ...

Looking for an easy solution in RegExp - how to locate the keys?

Similar Inquiries: Retrieving query string values using JavaScript Utilizing URL parameters in Javascript I am tasked with extracting specific keys from a series of URLs where the key is denoted by 'KEY=123'. My goal is to identify and e ...

What could be the reason for the list being undefined even though I explicitly defined it within the <script setup> section of my Nuxt 3 Project?

I am currently working on a Nuxt 3 Project and have created a component that generates a variable amount of elements. When calling the element, it is passed an array as a parameter. In the script setup, I define this array as 'list' and intend to ...

When generating a docx file with html-docx-js, it lacks the capability to incorporate external CSS class styles into the document

I have been utilizing the html-docx-js module to convert html content into docx format. However, I am facing an issue where most of my CSS is externally loaded and html-docx-js does not apply any styles. Here is a simplified code sample: const html = &ap ...

Dynamically load scripts in angularJs

Having multiple libraries and dependencies in my angularjs application is posing a challenge as I want to load them all using just one script, given that three apps are utilizing these dependencies. Currently, I have this custom script: var initDependenci ...

Update article translation dynamically in Vue without needing to refresh the page

ArticleController public function index() { $locale = Lang::locale(); // $locale = Lang::getLocale(); $articles = Article::withTranslations($locale)->get(); return $articles; } resources/assets/js/pages/articl ...

The issue of onClick failing to function when paired with the addEventListener for the

Looking into a react component for a profile button that opens a menu with three options: My Profile, Settings, and Logout. The issue seems to be with the onClick event on the a tags not working as expected (the console.log is not being printed). Interes ...

Is there a way to dynamically apply multiple classes to a <span> element in Vue.js and Tailwind based on an element from an array?

I've got an array in my JavaScript file that contains a list of national parks along with their visitation status. var parksList = new Vue({ el: "#parks", data: { parks: [ { name: "Acadia", state: "Maine", s ...

The method "_super" is not supported by the object in igGrid

When using infragistics and igGrid in my application, I encountered a javascript error. The error message reads: "Object doesn't support property or method "_super" Although I understand how to resolve this issue, I have decided to provide a fake ...

Passing the value of an Angular component to a different component

I have a menu in my application that uses IDs to route content, and I also have a detailed view where the content should be displayed based on those same IDs. Currently, I am trying to display objects by their ID when a button is clicked. However, I' ...

Creating dynamic height based on width using JavaScript

I'm trying to make a rectangle responsive based on the width of the window. This is my current logic: aspectRatio = 16 / 9 win = { width: window.innerWidth, height: window.innerHeight, } get browser() { const width = this.win.width - 250 ...

How can we properly access the DOM element generated by an {#each} loop in Svelte when it is clicked?

Using Svelte's {#each} functionality, I am reactively loading elements in the following way: {#each $items as item} <div> <Button on:click={someFunction}>{item.text}</Button> (*) </div> {/each} (*) a component t ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

Exporting Rendered HTML from a v-html Component in Vue

Utilizing the library sheetjs, I am generating HTML from an Excel range by utilizing the function sheet_to_html(). This generated HTML is then used to display a table using the v-html directive. Users can interact with the table by adding or removing class ...

Using a combination of jQuery and JavaScript to switch image tags between different classes

I'm really struggling with this issue and could use some guidance. Essentially, I have a code that should change the class of an img tag when a user clicks on a div element. Let's take a look at the HTML structure: <li><img src ...