xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

FileReader, readAsText

readastext filereader

FileReader.readAsText()

https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsText


    loadFile (file) {
      if (!file) return;
      log(`svg file`, file);
      const fr = new FileReader();
      // FileReader
      fr.readAsText(file);
      fr.addEventListener('loadend', (e) => {
        // this.clearFeatures();
        // this.addSVG(fr.result);
        log(`fr.result`, fr.result);
      });
    },
    // enter
    dragoverHandler (e) {
      e.preventDefault();
      this.hover = true;
      log(`over svg 图片`);
    },
    dragleaveHandler (e) {
      e.preventDefault();
      this.hover = false;
      log(`leave svg 图片`);
    },
    dropHandler (e) {
      // this.dragleaveHandler();
      e.preventDefault()
      this.hover = false;
      log(`drop svg 图片`);
      // 上传文件
      this.loadFile(e.dataTransfer.files[0]);
    },
    init() {
      // let dom = this.$el;
      let dom = this.$refs["svg-editor-box"];
      log(`dom ref`, dom);
      dom.addEventListener('dragover', this.dragoverHandler, false);
      dom.addEventListener('dragleave', this.dragleaveHandler, false);
      dom.addEventListener('drop', this.dropHandler, false);
   }


posted @ 2020-01-08 13:16  xgqfrms  阅读(1446)  评论(0编辑  收藏  举报