<el-upload
  class="upload-demo"
  action=""
  :http-request="addExcel"
  :show-file-list='false'>
  <el-button size="mini" type="primary">导入</el-button>
</el-upload>
addExcel(files){
	let that = this
	// FormData 对象
	var form = new FormData();
	form.append("file", files.file);// 文件对象
	
	// XMLHttpRequest 对象
	var xhr = new XMLHttpRequest();
	xhr.timeout = 30000; //设置超时
	xhr.open("post", '/yxcAdmin/hospital/add/excel', true);
	let token = sessionStorage.getItem('token')
	xhr.setRequestHeader('token', token);
	xhr.responseType = "json";
	xhr.onload = function () {
	 if (xhr.response.status != 0) {
	   that.$message.error(response.message)
	   return false;
	 }
	 that.$message.success('上传文件成功!')
	};
	xhr.ontimeout = function () {
	that.$message.error('数据加载失败,请刷新页面')
	};
	xhr.onerror = function (res) {
	that.$message.error('数据加载失败,请刷新页面')
	};
	xhr.send(form);
	// API.hospitalAddExcel().then(result=>{
	// 	if (result.status != "0") {
	// 		that.$message.error({
	// 			showClose: true,
	// 			message: result.message.toString(),
	// 			duration: 2000
	// 		});
	// 		return;
	// 	}
	// 	
	// }).catch(error=>{
	// 	this.$message.error(error.message)
	// })
	},
Logo

前往低代码交流专区

更多推荐