0

我正在努力使用 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;

4

1 回答 1

0

如果有人遇到类似的问题,我只是用 app js 和 vue 模板中的序列化替换了 objecttoformdata

import {serialize} from "object-to-formdata";
window.serialize=serialize;
于 2021-02-14T03:33:25.527 回答