Looking to switch my axios post call to a fetch call:
export async function createFriend ({
let myData = new FormData()
myData.append('name', name)
myData.append('age', age)
const response = await axios.post('/myApi/friends', myData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
return response.data.id
}
Trying to convert the above code to use fetch:
export async function createFriend ({
let myData = new FormData()
myData.append('name', name)
myData.append('age', age)
const response = await fetch('/myApi/friends', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data'
},
data: myData
})
return response.data.id
}
Encountering an issue with the new fetch call: Error in v-on handler (Promise/async): "TypeError: Cannot read property 'id' of undefined. This was not an issue with the axios call. Any idea what could be the problem?