electron在linux下遇到的几个问题
-
路径问题
在写代码导入模块的时候,路径一定要区分大小。比如新建文件的时候conversationList.vue 是这样的,但是在导入的时候使用ConversationList在win平台编译的时候不会报错,但是在linux下就会报错。所以在开发的过程中一定要注意代码规范,严格区分大小写。
-
remote undefined问题
在模块中使用remote进行通信的时候增加如下参数配置,否则在linux下会报remote undefined的错误。
-
读取本地文件问题
在系统中如果我们使用src 来引入file://本地目录//xx.png 等类似资源,需要增加两个配置
- 增加webSecurty:false 参数
webPreferences: { webSecurity: false, /**实现跨域请求 */ nodeIntegration: true /**使用nodejs其他模块 */, enableRemoteModule:true //解决linux remote 无法获取问题 }
- 在index.js增加如下方法
import { protocol } from "electron";
app.whenReady().then(() => {
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = decodeURI(request.url.replace('file:///', ''));
callback(pathname);
});
});