JSFiddle - React, Tailwind, and code Playground

by gitamgadtaula

HTML

<!DOCTYPE html>  
 <html lang="en" dir="ltr">  
  <head>  
   <meta charset="utf-8">  
   <title></title>  
  </head>  
  <body>  
	
   <div class="cart">  
	 <h1>
	  Todo
	 </h1>
    {{myText}} <br />  
    <input type="text" v-model="myText" value="" @onclick="add()">  
    <button @click="add()">Add todo</button>  
    <hr>  
    <span v-for="item in myArray"> {{item}} <button @click="deleteFunc(item)">remove</button>  
     <hr><br /></span>  
   </div>  
  </body>  
 </html>

CSS

body{
	background-color: purple;
	color: white;
}input{
	padding: 5px;
}
button {
	margin-top: 2px;
	padding: 4px;
	background-color: #ad34fa;
	border-radius: 4px;
	display: block;
}
h1{
	color:white;
}

JavaScript

new Vue({  
  el: '.cart',  
  data: {  
   items: 0,  
   myText: '',  
   myArray:[],  
  },  
  methods: {  
   add()  
   {  
    this.myArray.push(this.myText);  
    console.log('added inside the array');  
   },  
   deleteFunc(id)  
   {  
    console.log('remove function called');  
    this.myArray.splice(this.myArray.indexOf(id), 1);  //removes 1 element of the given index
   }  
   }  
 });