账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue 如何使用Electron 模块
    22
    0

    官方demo是

    const BrowserWindow = require('electron').remote.BrowserWindow
    const newWindowBtn = document.getElementById('frameless-window')
    
    const path = require('path')
    
    newWindowBtn.addEventListener('click', function (event) {
      const modalPath = path.join('file://', __dirname, '../../sections/windows/modal.html')
      let win = new BrowserWindow({ frame: false })
      win.on('close', function () { win = null })
      win.loadURL(modalPath)
      win.show()
    })

    但是实际怎么加呢? 我把const转为import from的方式导入到需要的页面提示fs模块找不到,webpack配置跳过检测但是Electron会报错。

    import BrowserWindow from 'BrowserWindow'
    import path  from 'path'
    methods: {
        click() {
            const BrowserWindow = BrowserWindow.remote.BrowserWindow
            const modalPath = path.join('file://', __dirname,'../../sections/windows/modal.html')
            let win = new BrowserWindow({ frame: false })
            win.on('close', function () { win = null })
            win.loadURL(modalPath)
            win.show()
        }
    }

    就是添加一个关闭窗口的按钮

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 长弓难鸣 普通会员 1楼

      要在 Vue 中使用 Electron 模块,首先需要在项目中安装 Electron,然后使用 npm 安装 Vue 的 Electron 版本。以下是一个简单的步骤:

      1. 安装 Electron: 在命令行中,输入以下命令来安装 Electron:

      npm install -g electron

      1. 安装 Vue: 在命令行中,输入以下命令来安装 Vue:

      npm install -g vue-cli

      1. 创建一个新的 Vue 应用项目: 在命令行中,输入以下命令来创建一个新的 Vue 应用项目:

      vue create my-project

      1. 进入项目目录: 在命令行中,输入以下命令来进入项目目录:

      cd my-project

      1. 运行 Vue 应用: 在命令行中,输入以下命令来运行 Vue 应用:

      npm run serve

      1. 运行 Electron 应用: 在命令行中,输入以下命令来运行 Electron 应用:

      node dist/index.html

      在上述命令中,dist/index.html 是 Electron 应用的 HTML 文件,该文件包含了 Electron 应用的主要界面。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部