New ways to update Vue.js data without the need to bind HTML to methods

In my Vue.js application, I have a file where users can choose from different graphs by setting the activeOrderView variable through a @click event. Each graph has its own set of x-axis categories and y-axis values.

The issue I am facing is that when a user selects a different graph, the data for that graph is not being updated. The data is fetched from the data() function and then updated using two functions within the methods. However, even after selecting a new graph, the original data remains the same. How can I ensure that the data is updated when a different graph is selected? It's worth noting that I'm using the Vue-apexchart component, so binding the methods directly to the HTML template is not an option.

Here is a snippet of the HTML template:

<b-tabs card fill>
    <b-tab title="Popular products" :title-link-class="'tab-title-class'" @click="activeOrderView = 'popularProducts'" active>
        <div v-if="activeOrderView === 'popularProducts'">
            <apexcharts type="bar" :options="chartOptions" :series="series"></apexcharts>
        </div>
    </b-tab>
    ...
</b-tabs>

And here is a snippet of the script:

<script>
import VueApexCharts from 'vue-apexcharts'

export default {
    // Component setup
    // Data and methods definitions
        
    created() {
        this.getOrderCategories();
        this.getOrderData();
    }
}

If anyone can provide insight on how to solve this problem, it would be greatly appreciated. Thank you!

Answer №1

To efficiently handle switching views, it is recommended to call the getOrderCategories() and getOrderData() functions.

It's advisable to create a method to avoid cluttering your code with multiple @click expressions.

Consider the following implementation:

methods: {
  // snip
  switchActiveOrderView(view) {
    this.activeOrderView = view;
    this.getOrderCategories();
    this.getOrderData();
  }
}

When defining tabs in your component:

<b-tab 
  title="Popular products" 
  title-link-class="tab-title-class"
  @click="switchOrderView('popularProducts')"
  active>

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

Creating a header upon clicking a link

Is it feasible to establish a request header when a user clicks on a link? ...

Sending an error to a component

My current issue involves the AddComment.vue component, which contains a form that submits data to a Laravel API endpoint for validation. If the validation fails, I need to display the errors within the AddComment.vue component. How can I access and return ...

The mobile web app on iOS is stuck in a never-ending loop of showing the

My mobile app is built using angular.js, Twitter Bootstrap, and grunt with a .NET back end. After logging in, the loading spinner keeps showing up constantly in the top nav next to the time and battery status. We make server calls at login through a factor ...

When using the `Document.write()` method, an error is returned stating, "Uncaught TypeError: Cannot read property 'document' of null"

I am currently integrating Angular2 into a website as the front-end framework, and it will be displayed on another website using an iframe. When working with the HTTP post method, I am able to receive a JSON response. Here is the API Post method that retu ...

The changes made to the state array in react.js are not reflected in the DOM

In my React game implementation, I have the board set up as a two-dimensional array in the initial state of the parent component. The tiles on the board are rendered by looping through this array. Each tile receives a function as a prop that allows it to m ...

Using the scroll feature in the selectyze plugin allows for smooth

The jQuery plugin selectyze from https://github.com/alpixel/Selectyze serves to replace the standard selectbox (dropdown), but there is a small issue that can be quite irritating. I am hoping someone out there may have a solution. Annoying Situation Here ...

Can you explain the functionality of `module.exports = mongoose model` in a NodeJs environment

Coming from a front-end React background, I am familiar with statements like import and exports. However, as I delve into learning Backend (NodeJs) with mongoDB, I find myself curious about the mechanics of import and export in this new environment. I hav ...

The function you are trying to execute in jQuery Mobile is not defined

I'm currently working on creating an external panel, but I've encountered some difficulties. Below is the HTML code: <html> <head> <title>My Page</title> <meta name="viewport" content="width=devi ...

Which is more effective: coding with just plain JavaScript and CSS, or utilizing frameworks?

As a student, is it more beneficial to focus on utilizing pure JavaScript & CSS or frameworks? And which approach is best suited for the professional field? ...

When using React.js, clicking on an answer option will change the color of all options, not just the one that was clicked

I'm currently working on my quiz page where all answer options change color when clicked. However, I only want the selected answer option to be colored based on its correctness. The data is being retrieved from a data.json array. export default functi ...

Having trouble running tests on the Express.js server

I'm struggling to run basic tests on my expressjs server and close it immediately. I have exported the server as a promise, but can't seem to figure out how to achieve this. Below is the code for my server file : index.js const config = require( ...

Is there a glitch preventing the connection between HTML and CSS in Notepad++ even though the link is correct?

I have encountered a puzzling situation that has left me scratching my head in confusion. Despite being a rookie, I've had experience with linking CSS files before and can't understand why it's not working this time around. This issue is per ...

What is the difference between achieving a mirror effect and a steel effect using Three.js?

When using three.js, I find myself a little confused about the concepts of metalness and roughness. Can someone explain the differences between metalness and roughness when applied to materials like mirrors and metals/steel? And furthermore, how can these ...

Finding a specific object within an array of objects by searching through a key value pair

In my collection, I have an array of objects structured as follows: [{ "businessunit": [{ "Area": [{ "Asset": [{ "Wells": { "Well": "Well 11" }, "name": "Field ...

The json_encode() function returned a JSON that is not valid

In my PHP file (although more complex, even with the simplest code it fails), I have: <?php $salida = array(1,2,3,4,5); echo json_encode($salida); ?> The response received is: [1,2,3,4,5] While this appears valid, it's actually not. When pas ...

Is there a way to halt the Vue Nuxt development server from running in the VS Code Console?

When using Vue Nuxt, I usually launch the development server with the command "npm run dev". However, I am looking for a way to stop the server from the VS Code console. Currently, the only method I know is to close the Terminal Window. Is there a better ...

Having trouble setting the selected option in Jquery by value?

I have exhausted all options found on the internet. What could I be overlooking? The desired option is not getting selected. Here is the troublesome section of code. I have also included some other attempts that I have commented out. If it helps, this li ...

Integrate yaml-loader into the i18n settings of a Vue-CLI 3 project

After diving into the Vue-i18n library and exploring this tutorial, I successfully incorporated tags in json format within my project created with vue-cli. While browsing through the documentation, I noticed an example using yaml instead of json. However ...

Using a variable as a URL parameter in a jQuery ajax request: tips and tricks

$.ajax({ type:"POST", url:"hostname/projfolder/webservice.php?callback=statusReturn&content="+str_table, contentType: "application/json; charset=utf-8", crossDomain:true, dataType:'jsonp', succe ...

Verify whether the variable is defined or present within the Angular controller

In my Angular controller, I have the following function: $scope.sendCompanyData = function() { delete $scope.company["step1Form"]; delete $scope.company["step2Form"]; delete $scope.standard_address["state"]; $http.post(Routing.generate(&a ...