鍍金池/ 問答/HTML/ elementui上傳問題,急急急!!!!

elementui上傳問題,急急急!!!!

上傳的標簽是這樣的寫的。

<el-upload
    class="upload-demo"
    ref="uploadNewFile"
    :action="actionUrl"
    :file-list="fileList"
    :auto-upload="false"
    :on-change="newFileChange"
    :on-remove="removeFile"
    :data="newFileData"
    name="files"
    :on-preview="handlePreview">
    <el-button type="primary" class="button b2 upload">
    <i class="iconfont icon-shangchuan"></i> 上傳
    </el-button>
    <el-input style="display: none" v-model="formData.newFile"></el-input>
</el-upload>

提交的時候

saveIt: function () {
                this.$refs['newAddForm'].validate((valid) => {
                    if(valid){
                        if (this.fileNameCheckFlag) {
                            this.newFileData.dictionaryName = this.formData.fileName;
                            this.newFileData.indexName = this.formData.fileName;
                            this.newFileData.isPublish = false;
                            this.newFileData.menuId = 256;
                            this.$refs['newAddForm'].resetFields();
                            this.zDialog.showAdd = false;
                            this.$refs.uploadNewFile.submit();
                            }
                    }

但是上傳文件提交的時候需要帶上 this.newFileData.title(文件名),和 this.newFileData.sort(文件排序號);
請問上傳多個文件的時候文件名和文件排序號怎么賦值? 在哪里賦值?

回答
編輯回答
萌面人

newFileChange函數(shù)里面獲取文件并append title和sort
var file = document.querySelector('[type=file]');

       
       
        var formData = new FormData();
  
        formData.append('file', file.files[0]);
        formData.append('title','你的title')
        formData.append('sort','你的序號')
        this.fileList=[];
        this.fileList.push({
            name:file.files[0].name,
        })
       this.file=formData
2017年12月28日 19:19