input实现文件上传

100 阅读1分钟
<div class="upload" @click="clickFile('fileInput')">
     <i class="el-icon-plus"></i>
</div>
<input type="file" ref="fileInput" id="fileInput" @change="handleFileInputChange" v-show="false">


// 模拟按键
        clickFile (refName)  {
            const input = document.getElementById(refName);
            input.click();
        },
        // 文件上传
        handleFileInputChange(){
            let formatDate = new FormData();
            const uploadedFile = this.$refs.fileInput.files[0];
            console.log('uploadedFile', uploadedFile);
            formatDate.append("file", uploadedFile);
            importFile(formatDate).then(res => {
                console.log('res',res);
            })
        },