Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 1.29 KB

summary.md

File metadata and controls

37 lines (31 loc) · 1.29 KB

加载本地文件

vue-cli-plugin-electron-builder中默认是无法加载本地文件的,但是官方不推荐禁用 WebSecurity,而是推荐在background.(js|ts)中配置

配置方法
//background.js
app.on('ready', () => {
  registerLocalResourceProtocol()
  ...
})

function registerLocalResourceProtocol() {
  protocol.registerFileProtocol('local-resource', (request, callback) => {
    const url = request.url.replace(/^local-resource:\/\//, '')
    // Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
    const decodedUrl = decodeURI(url) // Needed in case URL contains spaces
    try {
      return callback(decodedUrl)
    }
    catch (error) {
      console.error('ERROR: registerLocalResourceProtocol: Could not get file path:', error)
    }
  })
}

然后在本地文件前加上前缀local-resource://,比如<img src="local-resource://image.png"/>

官方链接: Loading Local Images/Resources

错误处理

音频错误

Error in v-on handler: "TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite."

原因:赋给currentTime的值是NaN类型