要使用的插件mammoth
安装
NPM install--只能预览savemammothtip: docx文件
(只能转换. docx文档,转换过程中复杂的样式会突然居中、首行缩进等)
完整的代码
templatedivclass=' word-wrap ' divid=' word view ' v-html=' wordtext '/div/template script///docx文档预览wordtext: ',word URL : ' vue-mobile/media/word.docx ' /文件地址};created () { this.getWordText;methods : { getword text (} { const xhr=newxmlhttprequest ); xhr.open('get ',this.wordURL,true ); xhr.responseType='arraybuffer '; xhr.onload=() (if ) xhr.Status==200 ) mammoth.converttohtml ) Arraybuffer3360newuint8Array ) xhr.responsponsponssion ); }; xhr.send (; (,);/scriptstylelang=' less '.word-wrap { padding :15 px; img { width: 100%; }}/style通过改变颜色可以改变标签
原来文: https://www.cn blogs.com/zjianfei/p/14862952.html