天天看点

element-ui 自定义上传文件

<el-upload
	action=""
	:on-change="handleChange"
	:http=request="uploadFile">	
</el-upload>
data() {
	return {
		// 上传的文件
		file: {}
	}
}
methods:{
	// 上传文件,获取文件流
	handleChange(file) {
		this.file = file.raw
	}
	// 自定义上传
	uploadFile() {
		// 创建表单对象
		let form = new FormData();
		// 后端接受参数 ,可以接受多个参数
		form.append("file",this.file)
		form.append(" "," ")
		this.$axios({
			data:from ,
			url: "后端接口地址",
			method: "method"
		})
	}
}

           

继续阅读