首页 > 其他分享 >原生get请求读取本地json文件,electron vue

原生get请求读取本地json文件,electron vue

时间:2022-08-17 14:34:06浏览次数:51  
标签:vue XMLHttpRequest 读取 get json xhr electron readLocalFile null

 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

相关文章