JSFiddle - React, Tailwind, and code Playground
by suatatan
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.24/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!--add new item template-->
<template id="add-item-template">
<div class="input-group">
<input v-model="newItem" placeholder="add shopping list item" type="text" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Add!</button>
</span>
</div>
</template>
<!--list item template-->
<template id="item-template">
<li :class="{ 'removed': item.checked }">
<input v-model="item.checked" type="checkbox">
<span>{{ item.text }}</span>
</li>
</template>
<!--items list template-->
<template id="items-template">
<item-component v-for="item in items" :item="item"></item-component>
</template>
<!--change title template-->
<template id="change-title-template">
<em>Change the title of your shopping list here</em>
<input v-model="title"/>
</template>
<!--main container markup-->
<div id="app" class="container">
<h2>{{ title }}</h2>
<add-item-component :items="items"></add-item-component>
<items-component :items="items"></items-component>
<div class="footer">
<hr/>
<change-title-component :title="title"></change-title-component>
</div>
</div>
CSS
.container {
width: 40%;
margin: 20px auto 0px auto;
}
.removed {
color: gray;
}
.removed span {
text-decoration: line-through;
}
ul li {
list-style-type: none;
}
ul li span {
margin-left: 5px;
}
.footer {
font-size: 0.7em;
margin-top: 40vh;
}
JavaScript
var data = {
items: [{ text: "Bananas", checked: true }, { text: "Apples", checked: false }],
title: "My Shopping List",
newItem: ""
};
//add item compoennt
Vue.component("add-item-component", {
template: "#add-item-template",
props: ["items", "newItem"]
});
//item component
Vue.component("item-component", {
template: "#item-template",
props: ["item"]
});
//items component
Vue.component("items-component", {
template: "#items-template",
props: ["items"]
});
//change title component
Vue.component("change-title-component", {
template: "#change-title-template",
props: ["title"]
});
new Vue({
el: "#app",
data: data,
methods: {
addItem: function () {
var text;
text = this.newItem.trim();
if (text) {
this.items.push({
text: text,
checked: false
});
this.newItem = "";
}
}
}
});