main.js
//全局数据
global.constantObject = {
name:"aaa"
};
a.js
const remote = require('electron').remote;
let btna = document.querySelector('#btna');
btna.onclick = function(event,msg){
console.log("btna"+msg);
console.log(remote.getGlobal('constantObject').name);
console.log("改变数据");
remote.getGlobal('constantObject').name = "cccc";
};
b.js
const remote = require('electron').remote;
let btnb = document.querySelector('#btnb');
btnb.onclick = function(event,msg){
console.log("btnb"+msg);
console.log(remote.getGlobal('constantObject').name);
};
index.html
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>news</title>
</head>
<body>
<h1>hello</h1>
<input id="btn" type="button" value="点我啊">
<input id="btna" type="button" value="btna">
<input id="btnb" type="button" value="btnb">
<!--1 引入render.js -->
<!-- <script src="./render-process/render.js" ></script> -->
<!-- electron 基于node -->
<script>
require('./render-process/render.js')
require('./render-process/a.js');
require('./render-process/b.js');
</script>
<!-- 区别 require 引入的文件的最外层的变量不是全局变量 src引入的是全局变量 -->
</body>
</html>