问题描述:
 
解决步骤: 1.之前想要在点击view按钮跳转时将xml文件的file对象传递给预览页在预览页进行读取xml内容,但是传递file对象很难实现(如果有人实现了 可以告诉我一下吗 学习下 感谢!) 2.之后我就在上传页那里进行读取xml文件 获取到他的文件内容(字符串类型),然后将字符串内容存储在session里(感觉不友好,但还没想到怎么解决,如有人知道 望告知 感谢!)。然后进行页面跳转到预览页
importInfo(param) {
var that = this
sessionStorage.removeItem('fileString')
...
getHtml(fd).then(res=>{
this.readXML(param.file)
})
}
toXmlView() {
if(sessionStorage.getItem('fileString')==null){
this.$message({
message: 'Wait a minute, getting the XML file',
type: 'warning'
});
}else{
let routeData = this.$router.resolve({
name: `uploadXml`,
});
window.open(routeData.href, '_blank')
}
},
readXML(files) {
let that = this
var reader = new FileReader();
console.log('files', files)
reader.readAsText(files, "UTF-8");
reader.onload = function (evt) {
var fileString = evt.target.result;
console.log('fileString-打印是字符串', fileString)
sessionStorage.setItem('fileString', fileString)
}
},
打印结果展示   (之前想在预览页通过fileString获取xmlDoc,直接使用xmlDoc页面展示,但不知道咋用=_=) 3.下载npm install vkbeautify --save(格式化xml字符串) npm i vue-highlight.js --save(调整样式且在xml标签里添加html标签 使之能在页面显示) 在main.js中引入
在预览页的vue页面中引入 import vkbeautify from ‘vkbeautify’ 
结果展示: 
|