2

I have a graph with a simple dropdown list with years and I need to pass the year whenever it's modified by the user so the graph will show that year's data.

For example, when I try to access the parameters from this method all i get is undefined:

fetchBarChartData({ anio, sort }) {
      var self = this;
      console.log(anio);
      fetch("https://demo8358110.mockable.io/year/" + this.anio) // insert your api call here
        .then(function(response) {
          var r = response.json();
          return r;
        })
        .then(function(data) {
          self.values = data.values;
          self.valuesline = data.valuesline;
          self.loaded = true;
        });

https://demo8358110.mockable.io/year/undefined

EDIT: I've added an example https://codesandbox.io/s/vue-template-x4z7b

2
  • Your example is a bit unclear but remove those curly brackets in the function call which are converting it into an anonymous object with data member anio and it should work. Commented Aug 30, 2019 at 18:12
  • I edited my answer with a sandbox. Commented Aug 30, 2019 at 18:51

1 Answer 1

2

You need to pass in the changed year to your fetchBarChartData function:

 <select name="year" v-model="year" @change="fetchBarChartData(year)">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.