uploadTxt.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div>
  3. <label for="uploadTxt" :class="$style.upload">
  4. <el-tooltip class="item" effect="dark" content="请选择格式为txt的原始数据文件" placement="top">
  5. <div :class="$style.btn"><i class="el-icon-upload"/>选择文件</div>
  6. </el-tooltip>
  7. <span :class="$style.file">{{ fileName }}</span>
  8. <input
  9. id="uploadTxt"
  10. type="file"
  11. accept=".txt"
  12. hidden
  13. @change="onChange"
  14. >
  15. </label>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. fileName: ''
  23. }
  24. },
  25. methods: {
  26. onChange(e) {
  27. const { files } = e.dataTransfer || e.target
  28. // console.log(files)
  29. this.fileName = files[0].name
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang="scss" module>
  35. .upload {
  36. // display: block;
  37. // width: 200px;
  38. .btn {
  39. display: inline-block;
  40. width: 100px;
  41. font-size: 12px;
  42. line-height: 20px;
  43. text-align: center;
  44. background-color: #409eff;
  45. color: #fff;
  46. border-radius: 5px;
  47. padding: 7px 15px;
  48. i{
  49. margin-right: 5px;
  50. }
  51. }
  52. .file {
  53. display: inline-block;
  54. font-size: 12px;
  55. color: #666;
  56. margin-left: 20px;
  57. }
  58. }
  59. </style>