convert size using vuejs [ bytes, kb, mb, gb ]

    By: Manu
    3 years ago
    Category: VuejsViews: 424

    To do this you will need to create a filter you can define filter like this

    filters:{
        sizeInMb(value){
            let  sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
            if (value == 0) return '0 Byte';
            let i = parseInt(Math.floor(Math.log(value) / Math.log(1024)));
            return Math.round(value / Math.pow(1024, i), 2) + ' ' + sizes[i];
        }
    },
    
    

    That's it now call this filter where you want to display size in mb,kb etc.

    <td>{file.file_size | sizeInMb}</td>
    

    Hope it helps