51 lines
1.6 KiB
Vue
51 lines
1.6 KiB
Vue
<template>
|
|
<div>
|
|
<h1>{{ toDoList.data.attributes.data.name }}</h1>
|
|
<div v-if="toDoList.data.attributes.data.to_dos.to_dos_count < 1">
|
|
------- no to Do -------
|
|
</div>
|
|
<div v-else v-for="toDo in toDoList.data.attributes.data.to_dos.data">{{ toDo.data.attributes.data.name }}</div>
|
|
<div>
|
|
<InputField name="name" classes="inline" placeholder="New To Do" required @update:field="name = $event" :errors="errors" />
|
|
<button class="btn-primary" @click="addToDo">ADD</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import InputField from "../../components/InputField";
|
|
|
|
export default {
|
|
name: "ToDoList",
|
|
components: {
|
|
InputField
|
|
},
|
|
data: function () {
|
|
return {
|
|
name: '',
|
|
errors: null,
|
|
}
|
|
},
|
|
props: {
|
|
toDoList: {
|
|
type: Object,
|
|
require: true
|
|
}
|
|
},
|
|
methods: {
|
|
addToDo: function () {
|
|
axios.post('/api/to-do-lists/' + this.toDoList.data.to_do_list_id + '/to-do', {name: this.name})
|
|
.then(res => {
|
|
console.log(res.data.data)
|
|
this.modal = false
|
|
this.name = ''
|
|
this.toDoList.data.attributes.data.to_dos.data.push(res.data)
|
|
})
|
|
.catch(errorRes => {
|
|
console.log('Internal Error, Unable to delete contact.' + errorRes)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|