使用element,
<el-upload class="upload-demo" :action="url_action_Cont" :on-preview="handlePreview"
:on-remove="handleRemove" :on-success="onsuccess" :ref="fileList"
accept=".doc,.docx,.pdf,.png"
:on-exceed="handleExceed" :file-list="fileList" :beforeUpload="beforeAvatarUpload">
<el-button size="mini" type="primary" >点击上传</el-button>
</el-upload>
以下是js,在beforeAvatarUpload之前传到另一个服务里
beforeAvatarUpload(file){
var formData = new FormData();//初始化一个FormData对象
formData.append("file", file);//将文件塞入FormData
console.log(formData)
$.ajax({
url: this.url_action,
type: "POST",
data: formData,
processData: false,
contentType: false,
success: function (responseText) {
}
});
}