• electron vue 模仿qq登录界面


    1、使用vuecli创建vue项目

    我用的vue2

    vue create qq_test
    

    2、安装electron

    1. npm install electron -g
    2. //or
    3. npm install electron@12.0.11 //老版本

    3、vue项目安装Electron-builder打包工具

    版本我选择的是12

    vue add electron-builder
    

    4、在vue项目的src下有个background.js文件

    background.js里面有默认的配置,修改后我的配置大概如下

    1. 'use strict'
    2. import { app, protocol, BrowserWindow, Menu, Tray } from 'electron'
    3. import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
    4. import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
    5. const isDevelopment = process.env.NODE_ENV !== 'production'
    6. // Scheme must be registered before the app is ready
    7. protocol.registerSchemesAsPrivileged([
    8. { scheme: 'app', privileges: { secure: true, standard: true } }
    9. ])
    10. async function createWindow() {
    11. // Create the browser window.
    12. const win = new BrowserWindow({
    13. width: 432,
    14. height: 331,
    15. alwaysOnTop: true,//窗口一直保持在其他窗口前面
    16. modal: true,
    17. frame: false,
    18. darkTheme: true,
    19. resizable: false,//用户不可以调整窗口
    20. center: true, // 窗口居中
    21. transparent: false,//窗口透明
    22. show: false,// 显示窗口将没有视觉闪烁(配合下面的ready-to-show事件)
    23. hasShadow: true,//窗口是否有阴影
    24. webPreferences: {
    25. // Use pluginOptions.nodeIntegration, leave this alone
    26. // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
    27. // nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
    28. // contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
    29. devTools: true,//客户端可以打开开发者工具(在客户端打开快捷键:ctrl+shift+i)
    30. nodeIntegration: true,
    31. enableRemoteModule: true, // 使用remote模块(electron12版本就开始废除了,需要我们自己安装remote模块)
    32. contextIsolation: false,
    33. //解决axios请求跨域问题(不推荐,不安全,但简单好用)
    34. webSecurity: false,
    35. },
    36. })
    37. if (process.env.WEBPACK_DEV_SERVER_URL) {
    38. // Load the url of the dev server if in development mode
    39. await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
    40. if (!process.env.IS_TEST) win.webContents.openDevTools()
    41. } else {
    42. createProtocol('app')
    43. // Load the index.html when not in development
    44. win.loadURL('app://./index.html')
    45. }
    46. }
    47. // Quit when all windows are closed.
    48. app.on('window-all-closed', () => {
    49. // On macOS it is common for applications and their menu bar
    50. // to stay active until the user quits explicitly with Cmd + Q
    51. if (process.platform !== 'darwin') {
    52. app.quit()
    53. }
    54. })
    55. app.on('activate', () => {
    56. // On macOS it's common to re-create a window in the app when the
    57. // dock icon is clicked and there are no other windows open.
    58. if (BrowserWindow.getAllWindows().length === 0) createWindow()
    59. })
    60. // This method will be called when Electron has finished
    61. // initialization and is ready to create browser windows.
    62. // Some APIs can only be used after this event occurs.
    63. app.once('ready-to-show', () => {
    64. win.show();
    65. })
    66. app.on('ready', async () => {
    67. if (isDevelopment && !process.env.IS_TEST) {
    68. // Install Vue Devtools
    69. try {
    70. await installExtension(VUEJS_DEVTOOLS)
    71. } catch (e) {
    72. console.error('Vue Devtools failed to install:', e.toString())
    73. }
    74. }
    75. createWindow()
    76. })
    77. // Exit cleanly on request from parent process in development mode.
    78. if (isDevelopment) {
    79. if (process.platform === 'win32') {
    80. process.on('message', (data) => {
    81. if (data === 'graceful-exit') {
    82. app.quit()
    83. }
    84. })
    85. } else {
    86. process.on('SIGTERM', () => {
    87. app.quit()
    88. })
    89. }
    90. }

    5、安装remote模块
    因为electron12版本开始就废除了remote模块,我们需要自己安装

    1. npm install @electron/remote --save
    2. //or
    3. cnpm install @electron/remote --save

    能在客户端实现 最大化、最小化、关闭功能

    6、代码

    1、Login.vue页面(登录页面)

    里面的最小化图标、关闭图标、最大化图标 请自己去 iconfont-阿里巴巴矢量图标库 下载

    1. <template>
    2. <div class="login" style="overflow:hidden;">
    3. <header class="header">
    4. <span &
  • 相关阅读:
    shell编程之循环
    无限磁力_给力的磁力搜索网站你都知道吗?
    Java并发编程吐血1个月总结最全面的100道面试题!!!
    Vue(贰)
    微电网两阶段鲁棒优化经济调度方法(完美复现)
    【安全狗漏洞通告】Apache Spark 命令注入漏洞方案
    Codeforces Round 929 (Div. 3 ABCDEFG题) 视频讲解
    KoP 正式开源:在 Apache Pulsar 上支持原生 Kafka 协议
    vue3 element plus表格导出为excel自定义表头
    [免费专栏] ATTACK安全之车机(Android)设备中监控命令执行的一些想法【概念篇】
  • 原文地址:https://blog.csdn.net/jcc4261/article/details/127897461