Skip to content

Commit

Permalink
新增拖拽文件到编辑区打开的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
pangqianjin committed Jun 25, 2021
1 parent 6b0d5bf commit 2d61098
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/MyMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
@keydown.ctrl.exact.native="handleKeyupCtrl($event)"
@keydown.tab.exact.native.prevent="handleKeydownTab($event)"
@keydown.ctrl.shift.exact.native.prevent="handleKeydownCtrlShift($event)"
@dragover.native.prevent
@drop.native.prevent="dropFile($event)"
v-model="text" autofocus :rows="22"></el-input>
</el-col>
<el-col :span="10">
Expand Down Expand Up @@ -63,6 +65,13 @@ export default {
this.addStyles({char1:'![]()',char2:'',wrap:false})
break
}
},
dropFile(event){// 拖放文件即读取
const file = event.dataTransfer.files[0]
const reader = new FileReader();
reader.readAsText(file, "utf-8");
reader.onload = ()=>this.text=''.concat(reader.result)
}
},
watch:{
Expand Down

0 comments on commit 2d61098

Please sign in to comment.