What's the proper way to handle forms in Electron?

前端 未结 3 1387
野趣味
野趣味 2021-02-11 19:48

The form html and submit event is part of the \"renderer\". The submitted data should be available in the main process. What\'s the proper way to submit the form and make that d

3条回答
  •  名媛妹妹
    2021-02-11 20:24

    Remote is great way to share data. Using global variables and share them with other pages of our electron application. So, based on the following IPC approach, I was able to manage it this way :

    1) Add this code in the main.js file :

       global.MyGlobalObject = {
          variable_1: '12345'
       }
    

    2) Use this on your 1st page to update global variable value :

    require('electron').remote.getGlobal('MyGlobalObject').variable_1= '4567'
    

    3) Lastly, use something like this on your 2nd page where you'll access the modified global variable and print it :

    console.log(require('electron').remote.getGlobal('MyGlobalObject').variable_1)
    

    You can find the same thing in electron's documentation.

提交回复
热议问题