1 readLocalFile(fileUrl) { 2 let xhr = null 3 if (window.XMLHttpRequest) { 4 xhr = new XMLHttpRequest() 5 } else { 6 // eslint-disable-next-line 7 xhr = new ActiveXObject('Microsoft.XMLHTTP') 8 } 9 const okStatus = document.location.protocol === 'file' ? 0 : 200 10 xhr.open('GET', fileUrl, false) 11 xhr.overrideMimeType('text/html;charset=utf-8') 12 xhr.send(null) 13 return (xhr.status === okStatus ? xhr.responseText : null) 14 15 },
// 读取本地配置文件 const readFile = JSON.parse(this.readLocalFile('文件路径'))
标签:vue,XMLHttpRequest,读取,get,json,xhr,electron,readLocalFile,null From: https://www.cnblogs.com/changshu/p/16595086.html