Is it necessary for Vue-EventBus to have its own dedicated function in order to work effectively?

Encountered a bug while transferring data using eventbus. What I attempted to do was pass the data from 'Quoteinput.vue' to 'Quotebar.vue' in order to update the progress bar length based on the data length present in 'Quoteinput.vue'.

This task was successfully accomplished by implementing two functions within 'Quoteinput.vue'.


One function is for pushing data to the array.
The other function is specifically for the eventbus.

Refer to the code snippet below.

=Quoteinput.vue=


<template>
  <div>
      <!-- <div class='input-group' style='position:relative'> -->
          <div class='input-group-prepend'>
              <span class = 'input-group-text'> Type your Quote</span>
          </div>


          <textarea class ='form-control' aria-label='with textarea' v-model="message"></textarea><hr><hr>
          <button class="btn btn-primary" @click='addingmessage'>submit my quote</button>
          <button class="btn btn-primary" @click='addprogress'>progresscheck</button>

          <textbox class='messagebox' v-for='value in quote' :typedquote ='value'></textbox>

          <!-- v model 이랑 v-for를 통해서 추가하면 되겠구만 -->
          <!-- Text box showing -->

  </div>
</template>

<script>
import textbox from './quotebox.vue'
import {ProgressBus} from '../../main.js'

export default {

    data(){
        return {
            quote:[],
            message:'',
        }
    },
    components:{
        textbox
    },
    methods:{
        addingmessage(){
            this.quote.push(this.message)

            // Progress bus retrieves the quote data here and passes it to Quotebar
        },
        addprogress(){
            ProgressBus.$emit('quotedata',this.quote)

        }
    }

}

However, this wasn't part of my initial plan. I attempted to combine progressbus and pushing the array into one function which is 'addingmessage()'. Like shown below.

methods:{
    addingmessage(){
        this.quote.push(this.message)
        ProgressBus.$emit('quotedata',this.quote)


    }

Why did this error occur? And how can I resolve it?

Below is the code responsible for rendering the progress bar.



=Quotebar.vue=

<template>


<div class="progress" style="height: 20px;">
  <div class="progress-bar" role="progressbar" :style="{width:10*completion+'%'}" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>

</template>

<script>
import {ProgressBus} from '../../main.js'

export default {

    created(){
        ProgressBus.$on('quotedata',(value)=>{
            this.completion= value.length 
        })
    },

    data(){
        return{
            completion: 0
        }
    }



}
</script>

<style scoped>


</style>

For better understanding, a simple diagram depicting the structure has been provided. https://i.sstatic.net/1YDpy.jpg

Answer №1

I wonder what the error message could be. Maybe using async/await functions will help execute tasks sequentially.

methods:{
    async addingmessage() {
        await this.quote.push(this.message);
        await ProgressBus.$emit('quotedata',this.quote);
    }
}

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

Tips on adding up polygon values in mapbox

After providing detailed information about my issue, I was criticized for seeking help, so I will be more general in my explanation. I am trying to calculate the sum of values for each location within a polygon drawn on Mapbox. I have the code to insert th ...

Customizing the title in Firebase-UI: Simple steps to override it

Currently, I am utilizing firebase with firebaseui to log into my React app. <StyledFirebaseAuth uiConfig={uiConfig} firebaseAuth={firebase.auth()} /> However, I have encountered an issue where I am unable to override the default Title (Sign in with ...

Combining Fields in Angular Filter to Enhance Search功能

I am facing a challenge with filtering a list of people based on their first and last name properties using Angular's filter functionality. The issue is that the filter only considers one property at a time, so users cannot search for both first and l ...

Obtaining data from JSON arrays

My current challenge involves extracting data from the following link: and storing it in my database. However, I am encountering difficulties with manipulating the array in order to retrieve the last unix datetime. Despite multiple attempts to extract th ...

Switch ng-model in Angular to something different

I am looking to transform my own tag into a template <div><input .../><strong>text</strong></div> My goal is to have the same values in both inputs. Check out the plunker here If I change the scope from scope: {value:' ...

Can a constant value be dynamically defined in Typescript?

Trying to dynamically define a constant in Typescript has proven to be more challenging than I anticipated. Here's what I attempted: define(name: string, value: any): boolean { var undef; const name = value; return name == undef; } ...

Tips for making immutable state changes in React

Is there a way to update specific content in the state without affecting all other data stored in the state? Just to provide some context: The function below is executed within another "handleChange" function that takes the event as input and assigns the ...

Using jQuery to redirect a page based on the IP address of the visitor

I am looking to implement Jquery code on the index page of www.propertyhere.com The aim is to redirect visitors based on their geographical IP location to specific pages: if the user's IP is from AU: http://www.propertyhere.com/Country/AU/search-t ...

"Troubleshooting a blank page issue in Angular UI Router caused by query string

I've been struggling with an issue related to query string parameters for quite some time. When I navigate to /, everything works perfectly fine. However, if I try something like /?anything, it simply doesn't work. These are the configurations in ...

Ingesting RSS feed into an Express server

I've been searching for hours, but I just can't seem to find a solution. I was able to figure things out when working on the client side, but now that I'm trying to load posts on the server and render them in the view, I'm hitting a roa ...

After completing a sequence, it does not reset

I'm working on creating a versatile "slideshow" feature that can be used for various elements. Currently, I am testing it on a div that contains paragraph text taken from my HTML document and represented as container1, container2, and container3. The ...

Slick Slider fails to load on web browsers

Hi everyone, I have a snippet of HTML code that I need help with: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css"/> </head> <body> ...

When the page is reloaded, Vuex state does not provide any feedback

The Vuex Authentication in my application is responsible for storing the state of signed-in user data. Everything works correctly during the sign-in process, but I encounter an issue when I reload the page. After reloading, the mutation payload returns n ...

Issues arise when attempting to use JavaScript to update the innerHTML content of a webpage

I have created a JavaScript code (shown below): function gup(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex ...

Executing AJAX to run JavaScript code

My website utilizes pushState for page loading. I am facing an issue where I want to incorporate JavaScript on a specific page, but the content is loaded via AJAX which prevents the script from functioning as intended. How can I resolve this situation? I h ...

What causes the "Cannot read properties of undefined" error in Vue when an array is initialized and output is still being displayed?

I am working with two vue files, namely App.vue and a component called UsersPage.vue. UsersPage.vue: <script> export default { data:() =>({ usersList : [] }), methods:{ async createUsersList(){ this.usersLi ...

eliminating the existing listener directly from EventM

Let's say I need to create an event listener with ghcjs-dom that triggers on a click and then removes itself. I have addListener :: (IsEventTarget t, IsEvent e) => t -> EventName t e -> SaferEventListener t e -> Bool -> IO ...

Maintaining responsiveness while initiating an HTTP request in a separate component

I have a specific app structure <header-bar></header-bar> <bag :bag="bag"></bag> <!--Main Section--> <section class="MainSection"> <div class="MainSection__wrap"> <router-view ...

Discovering country code details through the Geonames service API rather than relying on the HTML5 location object

My goal is to retrieve the country code of the user's current location using the Geonames Service API. However, it seems that the API only provides a two-letter country code instead of a three-letter one, which is what I require. To work around this i ...

Exchange SMS messages between server and web application

I'm currently based in Kenya and finding the pricing of Twilio to be quite high. My goal is to send and receive SMS messages, save them in a database, and showcase them on a web app. Do you think it's possible to create this using node.js? What w ...