[Vuejs]-Pass an argument from axios to a method vue

0๐Ÿ‘

โœ…

I get it finally and now works! here is the code, if someone have the same issue

    getData() {
  axios.get("something.xml").then((response) => {
    this.parseXML(response.data).then((data) => {
      this.flightInformations = data
    })
    .catch(err => {
      console.log(`${err} data is not avaiable`)
    })
  })
},
parseXML(data) {
  return new Promise((resolve) => {
    let parser = new xml2js.Parser({
      trim: true,
      explicitArray: true,
    });
    parser.parseString(data, (err, result) => {
     let obj = null
     if (this.$store.state.currentStep === 'abflug') {
      obj = result.flugplan.abflug[0].flug
     } else {
      obj = result.flugplan.ankunft[0].flug
     }
      let flight_dates = {};
      for (let item of obj) {
        let flight_date = item.datum.join().toString();
        if (!flight_dates[flight_date]) {
          flight_dates[flight_date] = [];
        }
        flight_dates[flight_date].push({
          flightNr: item.flugnr.join().toString(),
          flightPlace: item.ort.join().toString(),
          flightPlan: item.plan.join().toString(),
          flightExpected: item.erwartet.join().toString(),
          flightDate: item.datum.join().toString()
        })
      } 
      resolve(flight_dates)
    })
  })
}

Now using Store, when I change my CurrentStep, it also changes which part of XML it reads.

0๐Ÿ‘

Computed can only return some value instead of modifying anything.
Try this one:

computed: {
  someData() {
    return this.currentStep === 'departures' ? result.flugplan.abflug[0].flug : result.flugplan.ankunft[0].flug;
  }
}

After that use a someData value:

const obj = this.someData

Leave a comment