Vuejs2 如何将registerBufferProtocol与VueJS结合使用?

Vuejs2 如何将registerBufferProtocol与VueJS结合使用?,vuejs2,electron,Vuejs2,Electron,尝试将文件上载到我的Electron+VueJS应用程序,由此插件搭建: 我想上传一个文件,并使用registerBufferProtocol在我的渲染器(VueJS)中作为缓冲区获取它,但不确定这是否可行,而且我做得对 我找到了这个示例,并尝试将其修改为与 我现在的代码如下: 在background.js中,电子主流程: protocol.registerSchemesAsPrivileged([ { scheme: 'app', privileges: { secure: true, s

尝试将文件上载到我的Electron+VueJS应用程序,由此插件搭建:

我想上传一个文件,并使用
registerBufferProtocol
在我的渲染器(VueJS)中作为
缓冲区获取它,但不确定这是否可行,而且我做得对

我找到了这个示例,并尝试将其修改为与

我现在的代码如下:

background.js
中,电子主流程:

protocol.registerSchemesAsPrivileged([
  { scheme: 'app', privileges: { secure: true, standard: true } }
])

function registerSafeFileProtocol() {
  const safeFileProtocol = `${appName}-safe-file-protocol`
  protocol.registerBufferProtocol(safeFileProtocol, (request, callback) => {
    const url = request.url.replace(`${safeFileProtocol}://`, '')
    // Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
    const decodedUrl = decodeURIComponent(url);
    const file = fs.readFileSync(decodedUrl);
    try {
      return callback({ mimeType: 'application/epub+zip', data: file });
    }
    catch (error) {
      console.error('ERROR: main | registerSafeFileProtocol | Could not get file path', error)
    }
  })
}
在我的VueJS应用程序中:

methods: {
    loadBook (path) {
      const safePathToBookbook = `${appName}-safe-file-protocol://${path}`;

      //??? what should be done here to invoke `registerBufferProtocol` callback?

    }
},
mounted() {
    window.ipcRenderer.on('open-file-dialog-reply', (event, data) => {
      console.log(event, data);
      this.loadBook(data.file);
    })
  },
如何从渲染器(VueJS)调用
registerBufferProtocol
回调以获取
缓冲区