这里我是用的是element的upload组件

	<el-upload
      class="upload-demo"
      action="https://jsonplaceholder.typicode.com/posts/"
      :on-change="handleChange"
      :file-list="fileList"
    >
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
data() {
    return {
      username: "sss",
      textInfo: "",
      fileList: []
    };
  },
methods: {
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-3);
      let reader = new FileReader();
      reader.readAsText(file.raw, "UTF-8");// 如果出现乱码,可以更换编码
      if (typeof FileReader === "undefined") {
        alert("你的浏览器不支持");
        return;
      }
      reader.onload = function(e) {
        console.log(e.target.result);// [0317/205939.060:ERROR:crash_reporter_win.cc(92)] Unable to get pipe name for crashpad
      };
    }
  }

控制台输出内容

Logo

前往低代码交流专区

更多推荐