我正在努力使用 vue js 和 vform 验证具有图像的数据。我的问题是,我收到一个错误 app.js:2137 Uncaught (in promise) TypeError: objectToFormData is not a function。如何纠正这个问题:在 Vue
saveImageData(){
var self=this;
const config = {
headers: { 'content-type': 'multipart/form-data' }
}
document.getElementById('upload-file').value=[];
let formData = new FormData();
formData.append('title', this.form.title);
formData.append('price', this.form.price);
for(let i=0;i<this.form.images.length;i++){
formData.append('images[]', this.form.images[i]);
}
this.form.submit('post', '/senddata', {
// Transform form data to FormData
transformRequest: [function (formData, headers) {
return objectToFormData(formData)
}],
在 app.js 中
window.Vue = require('vue');
import { Form, HasError, AlertError } from 'vform'
import {objectToFormData} from 'object-to-formdata'
window.Form=Form;
window.objectToFormData=objectToFormData;