大家好!我叫戴向天
QQ羣:602504799
QQ:809002582
function readFileContent(path = null) {
if (!path) return false
return new Promise(function (resolve, reject) {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState == 4 && xhr.status == 200) resolve(xhr.responseText)
}
xhr.onerror = (e) => {
resolve(e)
}
xhr.open("get", path, true)
xhr.send(null)
})
}
使用方法
let context = await this.readFileContent("/index.html");
console.log(context)
效果圖