• 获取某个网址的文件内容


    比如想在本地获取到https://unpkg.com/element-ui@2.15.1/lib/theme-chalk/index.css这个文件的内容

     1       getFile (url, isBlob = false) {
     2         return new Promise((resolve, reject) => {
     3           const client = new XMLHttpRequest()
     4           client.responseType = isBlob ? 'blob' : ''
     5           client.onreadystatechange = () => {
     6             if (client.readyState !== 4) {
     7               return
     8             }
     9             if (client.status === 200) {
    10               const urlArr = client.responseURL.split('/')
    11               resolve({
    12                 data: client.response,
    13                 url: urlArr[urlArr.length - 1]
    14               })
    15             } else {
    16               reject(new Error(client.statusText))
    17             }
    18           }
    19           client.open('GET', url)
    20           client.send()
    21         })
    22       }
          getIndexStyle () {
            this.getFile('//unpkg.com/element-ui/lib/theme-chalk/index.css')
              .then(({ data }) => {
                this.originalStyle = this.getStyleTemplate(data)
              })
          },
  • 相关阅读:
    07周总结
    06周总结
    05周总结
    04周总结
    03周总结
    02周总结
    python数据特征预处理
    LeetCode Hard: 23. Merge k Sorted Lists
    LeetCode Hard: 4. Median of Two Sorted Arrays
    LeetCode Medium: 49. Group Anagrams
  • 原文地址:https://www.cnblogs.com/zhizhi0810/p/14734841.html
Copyright © 2020-2023  润新知