48 lines
1.4 KiB
Vue
Executable File
48 lines
1.4 KiB
Vue
Executable File
<template>
|
|
<div class="mx-2 p-2">
|
|
<form @submit.prevent="submitForm">
|
|
<div class="flex justify-between flex-center mb-4">
|
|
<router-link to="/memos/" class="btn">Back</router-link>
|
|
<button class="btn-primary">Add New Memo</button>
|
|
</div>
|
|
<div class="box">
|
|
<InputField name="name" label="Title" placeholder="Your Title" required @update:field="form.name = $event" :errors="errors" />
|
|
<TextAreaField name="memo" placeholder="Your Memo" required @update:field="form.memo = $event" :errors="errors" />
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import InputField from '../../components/InputField'
|
|
import TextAreaField from '../../components/TextAreaField'
|
|
|
|
export default {
|
|
name: 'MemoCreate',
|
|
components: {
|
|
InputField, TextAreaField
|
|
},
|
|
data: function () {
|
|
return {
|
|
form: {
|
|
'name': '',
|
|
'memo': '',
|
|
},
|
|
errors: null,
|
|
}
|
|
},
|
|
methods: {
|
|
submitForm: function () {
|
|
// eslint-disable-next-line no-undef
|
|
axios.post('/api/memos', this.form)
|
|
.then(response => {
|
|
this.$router.push(response.data.links.self)
|
|
})
|
|
.catch(errors => {
|
|
this.errors = errors.response.data.errors
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|