Почему-то форма не отправляет данные.
Компонент формы:
<template>
<div>
<div class="w-full ml-auto mr-auto text-center mt-7">
<h1 class="text-red-900 mb-7 font-bold text-2xl uppercase">event Creation Form</h1>
<form class="w-full" @submit.prevent="onSubmit">
<div class="mb-4">
<label for="title" class="block mb-2 text-sm font-medium text-gray-900">Title</label>
<my-input v-model:value="title" type="text" id="title" class="text-sm" placeholer="enter a title" required></my-input>
</div>
<div class="m-4">
<label for="description" class="block mb-2 text-sm font-medium text-gray-900">Description</label>
<my-input v-model:value="description" id="description" placeholder="enter a description" class="text-sm" type="text" required>
</my-input>
</div>
<div class="m-4">
<label for="startDate" class="block mb-2 text-sm font-medium text-gray-900">Start Date</label>
<my-input :min="Date.now()" v-model:value="startDate" id="startDate" placeholder="enter a startDate" class="text-sm" type="date" required>
</my-input>
</div>
<div class="m-4">
<label for="endDate" class="block mb-2 text-sm font-medium text-gray-900">End Date</label>
<my-input :min="Date.now()" v-model:value="endDate" id="endDate" placeholder="enter a endDate" class="text-sm" type="date" required>
</my-input>
</div>
<div class="mb-4">
<my-button>Save</my-button>
</div>
</form>
</div>
</div>
</template>
<script>
import MyInput from "@/components/UI/MyInput.vue";
import MyButton from "@/components/UI/MyButton.vue";
import {actionTypes} from "@/store/modules/add-event.";
export default {
name: "EventPostForm",
components: { MyButton, MyInput},
data(){
return {
title:'',
description:'',
startDate:'',
endDate:''
}
},
methods:{
onSubmit(){
this.$store.dispatch(actionTypes.addEvent,this.$route.params.id,{
title:this.title,
description:this.description,
startDate: this.startDate,
endDate:this.endDate
}).then(event=>{
console.log(event),
this.$router.push({name:'editUser'})
})
}
}
}
</script>
<style scoped>
</style>
Axios модуль:
import axios from "@/api/axios";
const getEvents=apiUrl=>{
return axios.get(apiUrl)
}
const addEvent=(id,credentials)=>{
return axios.post(`/user/${id}`,credentials)
}
export default {
getEvents,
addEvent
}
Vuex модуль:
import events from "@/api/events";
const state={
data: null,
isLoading: false,
error: null
}
export const mutationTypes={
addEventStart:'[add-event] addEventStart',
addEventSucess:'[add-event] addEventSucess',
addEventFailure:'[add-event] addEventFailure'
}
export const actionTypes={
addEvent:'[add-event] addEvent'
}
const mutations={
[mutationTypes.addEventStart](state){
state.isLoading=true
},
[mutationTypes.addEventSucess](state,payload){
state.isLoading=false
state.data=payload
},
[mutationTypes.addEventFailure](state,payload){
state.isLoading=false
state.error=payload
}
}
const actions={
[actionTypes.addEvent](context,apiUrl,credentials){
return new Promise(resolve => {
context.commit(mutationTypes.addEventStart)
events.addEvent(apiUrl,{credentials})
.then(response=>{
context.commit(mutationTypes.addEventSucess,response.data.events)
resolve(response.data.events)
})
.catch(err=>{
context.commit(mutationTypes.addEventFailure,err.response.data.errors)
})
})
}
}
export default {
state,
mutations,
actions
}
Ошибка:"Invalid Content-Type undefined"