Laravel+Vue 多图上传

Vue

<van-uploader v-model="fileList" upload-text="添加图片" :max-count="6" />
<van-cell>
    <van-button size="large" @click="onSubmit">提交</van-button>
</van-cell>
<script>
export default {
      data() {
        return {
          fileList: []
        };
      },
      created() {
        this.loadData();
      },
      methods: {
        onSubmit() {
          for( var i = 0; i < this.fileList.length; i++ ){
            let file = this.fileList[i];
            formData.append('images[' + i + ']', file.file);
          }
        }
      }
};
</script>


Laravel

//判断文件是否存在
if ($request->hasFile('images')) {
//循环Vue传过来的数组
    foreach ($request->file('images') as $image) {
        //操作
    }
}

 646 total views,  8 views today

Revisions

Comments are closed.