[Vuejs]-How to transform a data from an array with vuejs 2?

0👍

npm install moment –save then make sure to import it in the file where this.person object is. Use another .then() to add another field to the person object in the state use moment to diff the persons year born from the axios call and the year it is now. Use Moment to diff. Later you display the value on the age state, this way you still have birthday for something later, and the values from the DB are the same as the ones on the client.

 mounted() {
    axios.get('/persons/list')
        .then(response => {
            this.persons = response.data;
        })
        .then(()=>{
            this.persons.age = moment(this.persons.date_of_birth, "YYYYMMDD").fromNow();
        })
        .catch(error => {
            console.log(error)
            this.errored = true
        })
        .finally(() => this.loading = false)
}

Leave a comment