Code Hard
Code Hard

Reputation: 21

Converting datetime to date and displaying in vuejs input

I'm trying to convert a datetime result to date using split. But as much as it shows the date correctly without the time, it doesn't display in the input.

data(){
    return {
      date_created: String(this.date_created).split('T')[0],
      },
},
methods: {
      editItem (item) {
        this.date_created = item.society_date_created
        this.dialog = true
      },
},
created: function(){
                   axios.get(process.env.VUE_APP_Back+"/societies")
                        .then(response => {
                          this.society = response.data;
                        })
                        .catch(error => {
                          this.society = error.data;
                        });
                  this.loadTable= false;
},
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<input class="form-control" type="date" v-model="date_created" disabled>

Reponse date_created in api

2020-06-30T00:00:00.000Z

Upvotes: 0

Views: 403

Answers (1)

Paul Tsai
Paul Tsai

Reputation: 1009

You need to set this.date_created in your editItem method

data(){
  return {
    date_created: null
    },
},
methods: {
    editItem (item) {
      this.date_created = item.society_date_created.split('T')[0]
      this.dialog = true
    },
},

Upvotes: 1

Related Questions