更新时间:2023-01-30 15:11:40
您快到了.您唯一需要做的就是附加实际文件,并且应该将$ event传递给函数,如下所示:Submit($event)
You are almost there. The only thing you need is to append the actual file and you should pass $event to your function as: Submit($event)
Submit(event) {
let URL = '....'
let data = new FormData()
data.append('name', 'image')
data.append('file', event.target.files[0])
let config = {
header : {
'Content-Type' : 'multipart/form-data'
}
}
axios.post(URL, data, config).then(response => {
console.log('response', response)
}).catch(error => {
console.log('error', error)
})
}