Monday, March 4, 2019

How do I format date in a Vue component?

I would write method for that, and then where you need to format number you can just put method in template and pass value down 

methods:{

          format_date(value){
               if (value) {
                  return moment(String(value)).format('MM/DD/YYYY')
                   } 
             },

            format_time(row){
              if (row) {
                return moment(String(row)).format('h:mm A')
                } 
          },
     }

And then in template:

<template>
    <div>
        <div class="panel-group"v-for="(value,index) in list">
            <div class="col-md-8">
                <small>
                   <b>{{format_date(value.date) }}</b>
                </small>
                 <small>
                   <b>{{format_time(row.date) }}</b>
                </small>
            </div>
        </div>
    </div>
</template>



OR

date: { label: 'Date',render:(data) =>{return this.format_date(data) ? this.format_date(data) : " " }  },

No comments:

Post a Comment

Ajax load lage with laravel.

 step-1:  HTML <div class="row">                     <div class="col-lg-12">                           <d...