How to sort a json response in vue.js?

0 like 0 dislike
92 views
Here is the code I can't figure out how to call the sort if the data are from the file?(write in fact)

image
{{infos.departure_time}}
{{infos.stops}} TRANSPLANT{{infos.stops}} TRANSPLANT{{infos.stops}} DIRECT
{{infos.arrival_time}}
{{infos.origin}}, {{infos.origin_name}}
{{infos.destination_name}}, {{infos.destination}}
{{infos.destination_name}}
{{infos.departure_date}}
import ticketsData from "../assets/tickets.json";export default {name: "tikets",props: ["course", "translate"],data() {return {info: null,isActive: true};},mounted() {this.info = ticketsData.tickets;},methods: {convertCurrency(money) {return money / this.course;}},filters: {money: function(value) {return value.toFixed(2);},computed: {sortedInfo() {this.info = ticketsData.tickets;console.log(this.info);}}}};
by | 92 views

1 Answer

0 like 0 dislike
First, understand what is json. Characteristic a sign of ignorance - when people confuse json and the objects obtained by parsing json'and.

Secondly, why set the value of info takes place in mounted? What prevents to do it right in the data?

Third, you do not understand what computed properties (documentation, then tried to open?). Should return a value and not something they assign.

Fourthly, we need to sort - well sort:

computed: { sortedInfo() { return [...this.info].sort((a, b) => { // how to sort it - then you really know better }); }, },
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
110,608 questions
257,187 answers
0 comments
40,796 users