vue导入文件

<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)
	// })
	},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值