Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue Axios-使用bootstrapVue和vuex,上载文件和文本仍然存在问题?_Vue.js_Axios_Vuex_Bootstrap Vue - Fatal编程技术网

Vue.js Vue Axios-使用bootstrapVue和vuex,上载文件和文本仍然存在问题?

Vue.js Vue Axios-使用bootstrapVue和vuex,上载文件和文本仍然存在问题?,vue.js,axios,vuex,bootstrap-vue,Vue.js,Axios,Vuex,Bootstrap Vue,我有vue SPA,我正在尝试上传一些图像和文本。我尝试使用postman测试我的服务器代码和它的工作,但我的客户端仍然出错。 我想我还是被误认为是handlereq.file addImage.vue 要上载图像,必须设置内容类型并创建FormData,如下所示: let data = new FormData(); for (var i = 0; i < files.length; i++) { let file = files.item(i);

我有vue SPA,我正在尝试上传一些图像和文本。我尝试使用postman测试我的服务器代码和它的工作,但我的客户端仍然出错。 我想我还是被误认为是handlereq.file

  • addImage.vue

  • 要上载图像,必须设置内容类型并创建FormData,如下所示:

        let data = new FormData();
    
        for (var i = 0; i < files.length; i++) {
            let file = files.item(i);
            data.append('images[' + i + ']', file, file.name);
        }
    
        const config = {
            headers: { 'content-type': 'multipart/form-data' }
        }
    
        return axios.post('/api/images', data, config)
    
    let data=new FormData();
    对于(var i=0;i
    请显示您的错误代码。这是实际代码吗?因为我看到了许多不同的变量名……不,有些我改成了简单的。我尝试
    console.log(newImage)
    upper Axios,我得到了数据,但是
    console.log(newImage)
    在Axios下面。然后,结果是未定义的。我不确定,但是,你能试着去掉
    上的花括号吗?然后((newImage)=>{})
    您有关于codepen或其他类似服务的演示吗?
    actions: {
      addImage(context, newImage) {
        const config = {
          headers: {
            token: localStorage.getItem('token'),
          },
        };
    
        Axios
          .post(`${baseUrl}/product`, newImage, config)
          .then(({ newImage }) => {
            context.commit('ADD_IMAGE', newImage);
          })
          .catch((err) => {
            console.log(err.message);
          });
       }
    }
    
        let data = new FormData();
    
        for (var i = 0; i < files.length; i++) {
            let file = files.item(i);
            data.append('images[' + i + ']', file, file.name);
        }
    
        const config = {
            headers: { 'content-type': 'multipart/form-data' }
        }
    
        return axios.post('/api/images', data, config)