vue-element-admin tinymce thinkPHP 集成 上传图片 使用axios发送FormData数据 参数为空
关键:axioxs 有个参数 withCredentials 默认是 false 指定 true 就可以了
images_upload_handler(blobInfo, success, failure, progress) {
console.log('文件信息->', blobInfo.blob())
console.log('文件大小->', blobInfo.blob().size)
console.log('文件格式->', blobInfo.blob().type)
console.log('文件名称->', blobInfo.filename())
const formData = new FormData()
formData.append('file', blobInfo.blob())
formData.append('name', blobInfo.filename())
console.log('formdata->', formData)
const instance = axios.create({
withCredentials: true //这里是关键
})
progress(0)
instance.post('/backhome/upimg', formData).then(res => {
console.log('res->', res.data)
if (res.code === 20000) {
_this.$message({ message: res.data.message, type: 'success' })
success(res.data.data)
progress(100)
} else {
failure(res.data.message)
_this.$message({ message: res.data.message, type: 'danger' })
}
})
}