Saturday, December 13, 2025
HomeLanguagesJavascriptHow to dynamically add or remove items from a list in Vue.js...

How to dynamically add or remove items from a list in Vue.js ?

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. 

Using Vue.js one can easily add or remove items in a list dynamically using the v-model directive. This directive binds all the possibilities to a single channel. When the user selects an option from the list of available ones, it adds it to the list of values. Similarly, if the user deselects any option, it removes it from the list of values.

Example:

index.html




<html>
<head>
    <script src=
      </script>
</head>
<body>
    <div id='parent'>
      <h1 style="color: green;">
        neveropen
      </h1>
          
          <p><strong>Favourite Sports:</strong>
          </p>
  
        <input type="checkbox" id="cricket" 
               value="cricket" v-model="sports">
        <label for="cricket">Cricket</label>
        <input type="checkbox" id="football" 
               value="football" v-model="sports">
        <label for="football">Football</label>
        <input type="checkbox" id="hockey" 
               value="hockey" v-model="sports">
        <label for="hockey">Hockey</label>
        <input type="checkbox" id="badminton"
               value="badminton" v-model="sports">
        <label for="badminton">Badminton</label>
        <input type="checkbox" id="arching" 
               value="arching" v-model="sports">
        <label for="arching">Arching</label>
          
        <p><strong>Sports You  Like:</strong>
          {{ sports }}
        </p>
  
    </div>
    <script src='app.js'></script>
</body>
</html>


app.js




const parent = new Vue({
    el : '#parent',
    data : {
        sports : []
    }
})


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS