• electron另一种运行方式


    编写helloword

    全局安装软件

     npm install -g electron

    快速编写html

     html:5

     

     

    完整代码和流程:

    1.index.html

     <!DOCTYPE html>
     <html lang="en">
     <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
     </head>
     <body>
        <H1>hello word</H1>
     </body>
     </html>

    2.main.js

     var electron=require('electron')
     var app=electron.app//引用app
     var BrowserWindow=electron.BrowserWindow//窗口引用
     var mainWindow=null//声明打开的主窗口
     app.on('ready',()=>{
        mainWindow=new BrowserWindow({300,height:300})
        mainWindow.loadFile('index.html')//加载html
        mainWindow.on('closed',()=>{
            mainWindow=null
        })
     })
     

    3.生成package.json

     npm init --yes 

    后生成的json会根据本地的main.js改名

    4.运行代码

     electron .

    5.出现异常进行积极解决

     PS C:UsersplayerDesktop
    odeapp> electron .
     electron : 无法加载文件 C:UsersplayerAppDataRoaming pmelectron.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_
     Execution_Policies。
     所在位置 行:1 字符: 1
     + electron .
     + ~~~~~~~~
        + CategoryInfo         : SecurityError: (:) [],PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess

    解决方案:解决 cnpm : 无法加载文件 C:UsershpAppDataRoaming pmcnpm.ps1,因为在此系统上禁止运行脚本。

     以管理员身份运行power shell
     输入set-ExecutionPolicy RemoteSigned
     选择修改执行策略就能运行了

     

  • 相关阅读:
    2021/9/20 开始排序算法
    快速排序(自己版本)
    2021/9/17(栈实现+中后缀表达式求值)
    2021/9/18+19(中缀转后缀 + 递归 迷宫 + 八皇后)
    20212021/9/13 稀疏数组
    2021/9/12 线性表之ArrayList
    开发环境重整
    Nginx入门
    《财富的帝国》读书笔记
    Linux入门
  • 原文地址:https://www.cnblogs.com/q1359720840/p/14383657.html
Copyright © 2020-2023  润新知