Open In App
Related Articles

Filtering Weekdays and Weekends using Vue filters

Improve Article
Save Article
Like Article

Vue 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 supporting libraries.

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. 

To filter out weekdays and weekends in a week we have to write the filtering logic based on workdays and holidays. We use a switch-case for this and filter based on the names of the days.



  <script src=
  <h1 style="color: green;">
  <div id='parent'>
    <p><strong>{{day1}} : </strong
      {{ day1 | weeks }}
    <p><strong>{{day2}} : </strong
      {{ day2 | weeks }}
    <p><strong>{{day3}} : </strong>
      {{ day3 | weeks }}
    <p><strong>{{day4}} : </strong>
      {{ day4 | weeks }}
    <p><strong>{{day5}} : </strong>
      {{ day5 | weeks }}
  <script src='app.js'></script>


const parent = new Vue({
  el: "#parent",
  data: {
    day1: "Thursday",
    day2: "Tuesday",
    day3: "Sunday",
    day4: "Monday",
    day5: "Saturday",
  filters: {
    weeks: function (day) {
      // Using switch case to
      // decide between the days
      switch (day) {
        case "Monday":
        case "Tuesday":
        case "Wednesday":
        case "Thursday":
        case "Friday":
          return "It is Weekday, We have to work.";
        case "Saturday":
        case "Sunday":
          return "It is Weekend, We do not have to work.";


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 31 Mar, 2021
Like Article
Save Article
Similar Reads
Related Tutorials