Update index.vue

复用此组件时因为id不可重复的问题会导致onSuccess指向错误。
This commit is contained in:
zhaoguoweiLLHC
2018-09-27 12:02:32 +08:00
committed by GitHub
parent 98a8277a37
commit b2c9eb4f7b

View File

@@ -1,7 +1,7 @@
<template>
<div>
<input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" @change="handleClick">
<div id="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
<input class="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" @change="handleClick">
<div class="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
Drop excel file here or
<el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">Browse</el-button>
</div>
@@ -56,7 +56,10 @@ export default {
e.dataTransfer.dropEffect = 'copy'
},
handleUpload() {
document.getElementById('excel-upload-input').click()
// document.getElementById('excel-upload-input').click()
// 改成这样的原因是避免复用改组件时调用onSuccess时的指向错误。
// 因为之前代码为id取值复用组件时会导致id重复错误。所以去掉id取值改为refs样式用class解决。
this.$refs['excel-upload-input'].click();
},
handleClick(e) {
const files = e.target.files
@@ -126,11 +129,11 @@ export default {
</script>
<style scoped>
#excel-upload-input{
.excel-upload-input{
display: none;
z-index: -9999;
}
#drop{
.drop{
border: 2px dashed #bbb;
width: 600px;
height: 160px;