electron—Chromium有酒,Node有肉


谷歌V8引擎的出現,Node.js的誕生注定要把開發模式“攪亂”。

基於雲應用,服務化,定制化的應用需求不斷增加后使得傳統的winform開發空間越來越小,而原來做前端的空間越來越大,Node.js 的出現,讓所有做前端的同學眼前一亮,js可以寫服務器啦。

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^3.0.2"
  },
  "dependencies": {
    "element-ui": "^2.4.8",
    "leaflet": "^1.3.4",
    "mysql": "^2.16.0",
    "vue": "^2.5.17"
  }
}

  

const {app, BrowserWindow} = require('electron')
  
  // Keep a global reference of the window object, if you don't, the window will
  // be closed automatically when the JavaScript object is garbage collected.
  let win
  
  function createWindow () {
    // 創建瀏覽器窗口。
    win = new BrowserWindow({width: 800, height: 600})
  
    // 然后加載應用的 index.html。
    win.loadFile('index.html')
  
    // 打開開發者工具
    //win.webContents.openDevTools()
  
    // 當 window 被關閉,這個事件會被觸發。
    win.on('closed', () => {
      // 取消引用 window 對象,如果你的應用支持多窗口的話,
      // 通常會把多個 window 對象存放在一個數組里面,
      // 與此同時,你應該刪除相應的元素。
      win = null
    })
  }
  
  // Electron 會在初始化后並准備
  // 創建瀏覽器窗口時,調用這個函數。
  // 部分 API 在 ready 事件觸發后才能使用。
  app.on('ready', createWindow)
  
  // 當全部窗口關閉時退出。
  app.on('window-all-closed', () => {
    // 在 macOS 上,除非用戶用 Cmd + Q 確定地退出,
    // 否則絕大部分應用及其菜單欄會保持激活。
    if (process.platform !== 'darwin') {
      app.quit()
    }
  })
  
  app.on('activate', () => {
    // 在macOS上,當單擊dock圖標並且沒有其他窗口打開時,
    // 通常在應用程序中重新創建一個窗口。
    if (win === null) {
      createWindow()
    }
  })
  
  // 在這個文件中,你可以續寫應用剩下主進程代碼。
  // 也可以拆分成幾個文件,然后用 require 導入。

  

<!DOCTYPE html>
  <html>
    <head>
      <meta charset="UTF-8">
      <title>測試</title>
      <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
      <script src="https://unpkg.com/vue/dist/vue.js"></script>
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
	  <style>
	  #mapid { position:absolute;width:200px; height:200px; }
	  </style>
    </head>
    <body>
      <div id="app">
          <el-tabs v-model="activeName2" type="card" @tab-click="handleClick">
              <el-tab-pane label="用戶管理" name="first">
                  <el-table
                  :data="tableData"
                  stripe
                  style="width: 100%">
                  <el-table-column
                    prop="SAMPLEID"
                    label="日期"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="RESIDUAL"
                    label="姓名"
                    width="180">
                  </el-table-column>
                  <el-table-column
                    prop="LOSS"
                    label="地址">
                  </el-table-column>
                  <el-table-column
                    prop="WEIGHT"
                    label="其他">
                  </el-table-column>
                </el-table>

              </el-tab-pane>
              <el-tab-pane label="配置管理" name="second">配置管理</el-tab-pane>
              <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
              <el-tab-pane label="定時任務補償" name="fourth">定時任務補償</el-tab-pane>
            </el-tabs>

        
      </div>
	  <script>
     require('element-ui')
     
     var mysql = require('mysql');

     new Vue({
      el: '#app',
      data: function() {
        return { tableData: [],activeName2: 'first' }
      },
      mounted() {
        var _this = this;
        var connection = mysql.createConnection({
       host:'localhost',
       user:'root',
       password:'xxxx',
       database:'mydb',
       port:3306
     });
     connection.connect(function(err){
       if(err){
         console.log(err);
         return;
       }
     });
     connection.query('select * from users',function(err,rows){
       if(err){
         console.log(err);
       }
       console.log(rows);
       _this.tableData = rows;
     });
      }
    })
     
	   
	  </script>
    </body>
  </html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM