Adding Filters in VueJS Last Updated : 20 Nov, 2020 Comments Improve Suggest changes Like Article Like Report A Filter is a simple JavaScript function which is used to change the output of a data to the browser. Filters in Vue.JS don't change the data directly wherever we store them, it only applies formatting to our data. The data remains the same only the output of a data to a browser is changed. Vue.JS doesn't give these filters by default, so we have to make these filters. With Vue.JS , we can use filters in two different ways i.e. Global filter and Local filter. Global filter provides access all the components while Local filter only allows us to use our filter inside the component it was defined. Prerequisites: Basics of Vue.JS Approach: Below all the steps are described order wise to create Filters in Vue.JS . Step 1: Firstly if we want a global filter, we register it by Vue.filter() methodStep 2: Now we add Vue.filter() method in the index.js file . This filter function takes a value as the argument and then returns the filter or the transformed value .Vue.filter('uppercase', function(value)); Step 3: This function will be executed by Vue.JS whenever this filter is applied to something. This function will automatically receive one input one argument and that's the value . Vue.JS will pass this value to this function automatically and this will be the value on which we apply this filter.Step 4: Now we return the filter or the transformed value.Vue.filter('uppercase', function (value) { return value.toUpperCase(); }); Step 5: Now go to your template and simply add the filter by adding a pipe symbol and then the name of the filter. Syntax to apply a filter is{{ title | filtername }} Below is a sample program to illustrate the above approach: Global Filter: The scope of global filter is throughout our Vue app. Example 1: In the below program, we will reverse a given string using global filter. main.js JavaScript // GLOBAL FILTER // In this example, we are // creating a filter which // reverses the given string import Vue from "vue"; // Importing App.vue import App from "./App.vue"; // Declaration Vue.filter("reverseString", function (value) { return value.split("").reverse().join(""); }); new Vue({ render: (h) => h(App) }).$mount("#app"); App.vue HTML <!--Template--> <template> <div id="app"> <!--Applying filter--> <h1>{{ name | reverseString }}</h1> </div> </template> <script> export default { data: function () { return { name: "GEEKSFORGEEKS", }; }, }; </script> Output Local Filter: The scope of local filter is within a component. Example 2: In the below program, we will change given string to uppercase using local filter. App.vue JavaScript <!-- Local filter in VueJS --> <!-- Template --> <template> <div> <!-- Applying Uppercase filter --> <h1>{{ name| uppercase }}</h1> </div> </template> <!-- Filter defined locally --> <script> export default { data: function() { return { name: "geeksforgeeks" }; }, filters: { uppercase: function(value) { return value.toUpperCase(); } } }; </script> Output Comment More infoAdvertise with us Next Article Adding Filters in VueJS ritikumariupadhyay24 Follow Improve Article Tags : JavaScript Web Technologies Vue.JS Similar Reads How to Add List Items Onclick in VueJS ? In VueJS, we can make dynamic applications by adding list items on click. This allows for interactive user experiences where new items can be added to a list with a click event. The below approaches can be used to accomplish this task. Table of Content By creating a custom method to Add ItemsUsing I 2 min read Building a Shopping List with VueJS The following approach covers how to build a simple shopping list app with VueJs. Vue (or Vue.js) is an open-source JavaScript framework geared towards building user interfaces, it was created by Evan You.Prerequisites:Basic understanding of HTML.Basic knowledge of CSSBasic knowledge of JavaScriptIn 3 min read Sign Up Page in VueJS This project aims to create a Sign Up Page using Vue.js and Tailwind CSS. The page allows users to sign up by providing their name, email, and password and confirming the password. It provides a simple and intuitive interface for the users to input their information and complete the sign-up process. 2 min read How to Add Custom Fonts in VueJS ? Vue.js is a JavaScript framework used in building powerful and beautiful user interfaces. The key feature of Vue.js is its component-based architecture that allows the developers to create reusable and modular components. Custom fonts can bring uniqueness and visual appeal to your Vue.js application 2 min read Math Sprint Game in VueJS The Math Sprint Game is a simple web-based game designed to help users practice basic arithmetic operations such as addition and subtraction in a fun and interactive way. It generates random math problems for the users to solve within the limited time frame testing their mental math skills and agili 3 min read VueJS for backend developers As backend developers, diving into front-end technologies can be a challenging task. However, with the rise of JavaScript frameworks like Vue.js, the transition is becoming smoother. Vue.js offers a gentle learning curve and powerful features that align well with backend development principles. In t 7 min read Handling User Input in Vue.js Vue.js is a progressive framework for building user interfaces. The core library is focused on the view layer only and is easy to pick up and integrate with other libraries. Vue is also perfectly capable of powering sophisticated Single-Page Applications in combination with modern tooling and suppor 4 min read Explain Plugins in Vue.js VueJS is one of the best frameworks for JavaScript like ReactJS. The VueJS is used to design the user interface layer, it is easy to pick up for any developers. It is compatible with other libraries and extensions as well. If you want to create a single-page application, I think VueJS is the first c 3 min read v-bind Directive in Vue.js The v-bind directive is a Vuejs directive used to bind one or more attributes, or a component prop to an element. If that attribute is bound to our data defined in Vuejs instance then dynamic changes can be observed as data changes. First, we will create a div element with id as app, and let's apply 2 min read Building A Weather App Using VueJS We will explore how to create a weather application using Vue.js. We'll cover an approach to fetching weather data, displaying current weather conditions, and forecasting. By the end of this guide, you'll have a fully functional weather application that displays current weather information and forec 6 min read Like