electron + vue3

版本

vue 3 @3.0.0

electron @ 6.1.12

builder-util @22.10.5

问题1.运行打包命令-》Error: Cannot find module ‘fs/promises’

原因:node 版本不是最新,electron-builder中引用fs方式与老版本node的不一样。require(‘fs/promise’);node旧-require(‘fs’).promise

+DLL-------ffi-napi

问题2:
Uncaught Error: Dynamic Linking Error: Win32 error 126 at new DynamicLibrary
原因:引入dll文件路径不对

问题3:electron运行时报错 Uncaught ReferenceError: require is not defined; || Error: Module did not self-register.

	//在new BrowserWindow 创建窗口方法中添加 nodeIntegration:true, 
	webPreferences: {
       contextIsolation: false,
       nodeIntegration: true,  
   }
   //在vue.config.js中设置
   module.exports = defineConfig({
       pluginOptions:{
       electronBuilder:{
       nodeIntegration:true,
       },
       },
   })

问题5:Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=73 uv=1 libc=glibc node=12.4.0 electron=6.1.12 webpack=true
原因:在编译时排除ffi-napi,ref-napi两个依赖,这两个依赖包含c/c++代码,只在运行时启用.
解决:

module.exports = defineConfig({
  pluginOptions:{
    electronBuilder:{
      externals:[
        'ffi-napi',
        'ref-napi'
      ],
    },
  },
})

问题6:Uncaught TypeError: os.arch is not a function

 //在vue.config.js中设置
    module.exports = defineConfig({
        pluginOptions:{
        electronBuilder:{
        	nodeIntegration:true,
          },
        },
    })

问题7:npm run serve 运行时----$ BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.This is no longer the case. Verify if you need this module and configure a polyfill for it.

 //在vue.config.js中设置
    module.exports = defineConfig({
      configureWebpack:()=>{
            return {
              resolve:{
                fallback:{
                  "path": false,
                  "os":false,
                  "fs": false, }},} }
    })

问题8: npm run serve 运行时 --Uncaught ReferenceError: require is not defined

Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=73 uv=1 libc=glibc node=12.4.0 electron=6.1.12 webpack=true
loaded from: F:\arui\server\ecg-app\node_modules\electron\dist\resources\electron.asar

Electron是一个开源框架,用于构建跨平台的桌面应用程序,结合Vue.js和Vite(一个快速的前端构建工具)可以让您创建现代、高性能的Web视图层,嵌入到 Electron 应用中。RTSP(Real-Time Streaming Protocol)是一种网络协议,用于实时视频流传输。 要在 Electron + Vue3 + Vite 中实现 RTSP 播放,您可以按照以下步骤操作: 1. **安装依赖**: - 安装 `vue-video-player` 或类似的库,它提供了处理媒体流的功能,如 `vue-streaming-api`。 - 如果需要,安装支持 RTSP 解码的库,比如 `fluent-ffmpeg` 或 `mediasoup-client`。 ```bash npm install vue-video-player fluent-ffmpeg --save ``` 2. **设置配置**: 在项目中创建一个配置文件(例如 `config.js`),用于管理 RTSP 地址等信息。 ```javascript export default { rtspsource: 'rtsp://your_rtspserver_url/stream' } ``` 3. **在 Vue 组件中使用**: 使用 Vue 插件或组件内的方法加载并播放 RTSP 流。例如,使用 `vue-video-player`: ```html <template> <div id="player"> <VideoPlayer v-bind:src="config.rtspsource"></VideoPlayer> </div> </template> <script> import VideoPlayer from 'vue-video-player'; import { defineComponent, ref } from 'vue'; import config from '@/config'; export default defineComponent({ components: { VideoPlayer, }, setup() { const player = ref(null); // 当组件挂载后尝试播放 mounted() { player.value.play(); } return { player, }; }, }); </script> ``` 4. **错误处理**: 添加错误处理代码来捕获并处理播放过程中可能出现的问题,如连接失败、编码不兼容等。 5. **优化和调整**: 根据应用需求可能还需要对视频质量、缓冲策略等进行优化,并确保在不同平台上运行稳定。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值