Electron (Nodejs를 사용하는)에 두 개의 js 파일이 있는데 한 파일에서 내보내고 다른 파일에서 필요로합니다.메서드 및 속성을 사용하여 개체를 내보내는 방법
app.js : 나는 수출의 가능한 모든 방법을 시도
App = {
server: {
host: '192.168.0.5',
user: 'root',
}
ping: function() {
}
}
exports.App = App
, 등등 module.exports = App
, module.exports.App = App
등.
ping.js 첫 번째 시도 :
var App = require('../app.js') // I have also tried adding .App to the end
console.log(App) // This returns an object which contains the App object
ping.js 두 번째 시도 :
var App = require('../app.js')
App.x = 'y'
console.log(App) // this returns an object which contains the App object and the x property
App
다른 App
개체가 포함되어 나타날 수 있지만 console.log(App.App)
이 존재하지 않는 말했다.
문제점을 발견했습니다. index.html에서'require ('app.js')'를 사용하고 있었지만'ping.js'는'app.js'에서만 필요했습니다. index.html에'require ('ping.js')'를 추가했는데 성공했습니다. – Alex