JSFiddle - React, Tailwind, and code Playground
HTML
<section id="madplan" class="section-wrapper">
<section class="check-list">
<h1>Mandag</h1>
<list-component
v-on:addedtask='acknowledgeAddedTask'
v-on:removedtask='acknowledgeRemovedTask'
></list-component>
<h1>Tirsdag</h1>
<list-component
v-on:addedtask='acknowledgeAddedTask'
v-on:removedtask='acknowledgeRemovedTask'
></list-component>
</section>
<ul id="list">
<h2>list</h2>
<li v-for="task in subTaskList" v-bind:key="task.text" class="list-item">{{ task.text }}</li>
</ul>
</section>
CSS
* {
margin: 0;
padding: 0;
}
JavaScript
Vue.component('list-component', {
data: function() {
return {
newTask: "",
taskList: [],
newSubTask: "",
subTaskList: [],
};
},
template:
'<div>' +
'<section class="prefetch panel">' +
'<input v-if="showInput" class="input typeahead" type="text" placeholder="Tilføj ret til madplanen" v-model="newTask" v-on:keyup.enter="addTask">' +
'</section>' +
'<details v-for="task in taskList" v-bind:key="task.text" class="sub-list-item">' +
'<summary>{{ task.text }}<button v-on:click="removeSubTask(task)">X</button>' + '</summary>' +
'<input class="subInput" type="text" placeholder="Tilføj til indkøbsseddel" v-model="newSubTask" v-on:keyup.enter="addSubTask">' +
'</details>' +
'</div>',
computed: {
showInput: function() {
return !this.taskList.length
},
},
methods: {
//addTasks
//
addTask: function() {
var task = this.newTask.trim();
if (task) {
this.taskList.push({
text: task
});
this.newTask = "";
this.$emit('addedtask', task)
}
},
addSubTask: function() {
var task = this.newSubTask.trim();
if (task) {
this.subTaskList.push({
text: task
});
this.newSubTask = "";
}
},
//removeTasks
//
removeSubTask: function(task)...