vue 读取doc文档为html

核心插件

  1. mammoth : 将文档内容转化为html

  2. vue2-editor:富文本编辑器

核心方法: 

//文件切换事件
readFileInputEventAsArrayBuffer($event){
  console.log("event ==>"event);
  var file = event.target.files[0];
  var reader = new FileReader();
  let _this = this;
  reader.onload function(loadEvent){
    console.log("loadEvent",loadEvent);
    var arrayBuffer = loadEvent.target.result;  //arrayBuffer
    //mammothJs
    mammoth.convertToHtml({arrayBuffer:arrayBuffer }).then(res =>
      this.docForm.docHTML = res.value;
    })
  }   reader.readAsArrayBuffer(file);
}

 

posted @ 2023-12-15 11:33  张哲Zeo  阅读(351)  评论(0)    收藏  举报