Data Conversion to KB, MB, GB, TB using Vue.js filters
In this article, we are going to learn how to convert data to the given unit of data using filters in VueJS. Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filter is a function that accepts a value and returns another value. The returned value is the one that’s actually printed in the Vue.js template.
The abbreviation of the data values to KB, MB, GB, or TB can be done using a filter. The logic of the filter will first divide the value by 1024 raised to the power of a constant. For example, to convert the value in Kilobytes, the constant is assumed to 1, similarly, for a value in Megabytes, the constant value is 2, and so on.
The below example will demonstrate this approach:
Example: In this example, we will convert various values of bytes to the given unit of data given to the filter.