JSFiddle - React, Tailwind, and code Playground
Test Two - Vue
by Hugo Carneiro
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.6.0/Sortable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/15.0.0/vuedraggable.min.js"></script>
<div id="app">
<h2>To do: ({{todos.length}})</h2>
<input type="text" placeholder="Type something and press return"/ @keyup.enter="addTask" v-model="taskField">
<ol>
<draggable v-model="todos" :options="{group:'tasks'}">
<li v-for="(task, index) in todos" v-bind:key="index">
<label>
<input type="checkbox" v-model="checkedTasks" :value="task.text" @click="markCompleted(index)">
<span>{{task.text}}</span>
<a href="#" class="remove" @click="removeTask(index)">Remove</a>
</label>
</li>
</draggable>
</ol>
<hr />
<h2>
Completed items: ({{completed.length}})
</h2>
<ol>
<draggable v-model="completed" :options="{group:'tasks'}">
<li v-for="(task, index) in completed" v-bind:key="index">
<label>
<span>{{task.text}}</span>
</label>
</li>
</draggable>
</ol>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
input[type="text"] {
padding: 10px;
width: 200px;
}
label .remove {
display: none;
color: red;
}
label:hover .remove {
display: inline-block;
margin-left: 10px;
color: red;
opacity: 0.5;
}
Vue
new Vue({
el: "#app",
data: {
taskField: '',
checkedTasks: [],
todos: [
{ text: "Learn about Vue" },
{ text: "Learn about Fliplet" },
{ text: "Play around in JSFiddle" },
{ text: "Show us what you've got" }
],
completed: []
},
methods: {
addTask() {
const newTask = {
text: this.taskField
}
this.todos.unshift(newTask)
},
removeTask(index) {
this.todos.splice(index, 1)
},
markCompleted(index) {
const taskCopy = this.todos[index]
// Clears the checkboxes model
this.uncheckAll()
this.todos.splice(index, 1)
this.completed.unshift(taskCopy)
},
uncheckAll() {
this.$nextTick(() => {
this.checkedTasks = []
})
}
}
})