Skip to content

Instantly share code, notes, and snippets.

@aristotelesbr
Last active April 9, 2017 14:17
Show Gist options
  • Save aristotelesbr/bc9ff4625d8d61bbd0203efd96a8fb2d to your computer and use it in GitHub Desktop.
Save aristotelesbr/bc9ff4625d8d61bbd0203efd96a8fb2d to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/mujacey
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<title>JS Bin</title>
<style id="jsbin-css">
.xyz {
color: red
}
</style>
</head>
<body class="container-fluid">
<div id="app">
<hr>
<div class="col-xs-12">
<div class="panel panel-default">
<form class="panel-body"
v-on:submit.prevent="addTask()">
<div class="input-group">
<input type="text"
class="form-control"
v-model="newTask.title">
<span class="input-group-btn">
<button class="btn btn-primary"
v-on:click="addTask()"
:disabled="!canAddnewTask"
type="button">Add</button>
</span>
</form>
</div>
</div>
<table class="table">
<thead>
<tr>
<th colspan="2">Estados</th>
</tr>
</thead>
<tbody>
<tr v-for="task in tasks">
<td>
<input type="checkbox"
v-model="task.completed">
</td>
<td>{{ task.title }}</td>
</tr>
</tbody>
</table>
</div>
<hr>
<pre>{{ newTask }}</pre>
</div>
// Função para clonar o objeto fazendo com que o
// antigo perca sua referencia.
const clone = (obj) => JSON.parse(JSON.stringify(obj));
new Vue({
el: '#app',
data: {
tasks: [{
title: 'Task1',
completed: false
},{
title: 'Task2',
completed: false
}],
newTask: {},
},
computed: {
canAddnewTask() {
return this.newTask.title.length > 0;
}
},
methods: {
addTask(){
if(this.canAddnewTask) {
const task = clone(this.newTask)
this.tasks.unshift(task);
this.newTask = {};
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment