首页 > 解决方案 > TypeError:无法读取 ElectronJS 应用程序中未定义的属性“协议”

问题描述

我正在使用axios并将fs图像下载到本地目录。我正在使用 ElectronJS 和 VueJS 创建桌面应用程序。

async saveOptions() {

      var currentLightbox = this.currentLightbox
      var title = currentLightbox.data.title.replace(/\s/g, '_')
      console.log(title)



      var URL = currentLightbox.data.preview.images[0].source.url
      fs.mkdir('images/', {recursive: true}, (err) => {
        if (err) throw(err)
      })
      const Path = path.resolve('images/',  `${title}.jpg`)
      console.log(Path)
      const writer = fs.createWriteStream(Path)

      axios({
        url: URL,
        method: 'GET',
        responseType: 'stream'
      })
      .then((response) => {
        response.data.pipe(writer)
      })

    }

在下载时运行此功能,控制台给出以下错误:

Uncaught (in promise) TypeError: Cannot read property 'protocol' of undefined
    at isURLSameOrigin (isURLSameOrigin.js?3934:57)
    at dispatchXhrRequest (xhr.js?b50d:109)
    at new Promise (<anonymous>)
    at xhrAdapter (xhr.js?b50d:12)
    at dispatchRequest (dispatchRequest.js?5270:52)

什么可能导致这种情况?

标签: javascriptnode.jselectronaxios

解决方案


推荐阅读