<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Electron + Vue3 + TS + sqlite3項目搭建

      Electron + Vue3 + TS + sqlite3項目搭建

      基礎環境

      • node v16.15.0
      • npm v8.5.5
      • yarn v1.22.19

      安裝vue-cli

      $ npm install @vue/cli@5.0.8 -g
      // 等待安裝完成
      $ vue -V
      // @vue/cli 5.0.8
      

      創建vue項目

      $ vue create project
      

      選擇自定義配置

      Vue CLI v5.0.8
      ? Please pick a preset:
        Default ([Vue 3] babel, eslint)
        Default ([Vue 2] babel, eslint)
      > Manually select features
      

      選中自己項目需要的配置

      Vue CLI v5.0.8
      ? Please pick a preset: Manually select features
      ? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
       (*) Babel
       (*) TypeScript
       ( ) Progressive Web App (PWA) Support
       (*) Router
       (*) Vuex
       (*) CSS Pre-processors
       (*) Linter / Formatter
       ( ) Unit Testing
      >( ) E2E Testing
      

      選擇vue 3.x

      Vue CLI v5.0.8
      ? Please pick a preset: Manually select features
      ? Check the features needed for your project: Babel, TS, Router, Vuex, CSS Pre-processors, Linter
      ? Choose a version of Vue.js that you want to start the project with (Use arrow keys)
      > 3.x
        2.x
      

      后面各種配置參考

      Vue CLI v5.0.8
      ? Please pick a preset: Manually select features
      ? Check the features needed for your project: Babel, TS, Router, Vuex, CSS Pre-processors, Linter
      ? Choose a version of Vue.js that you want to start the project with 3.x
      ? Use class-style component syntax? No
      ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
      ? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
      ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass)
      ? Pick a linter / formatter config: Basic
      ? Pick additional lint features: Lint on save
      ? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
      ? Save this as a preset for future projects? No
      

      開始自動構建

      Vue CLI v5.0.8
      ?  Creating project in ***\project.
      ??  Initializing git repository...
      ??  Installing CLI plugins. This might take a while...
      // 等待項目構建
      

      集成Electron

      $ cd project
      $ vue add electron-builder
      // 等待vue-cli-plugin-electron-builder安裝
      

      選擇13.0.0版本繼續

      ? Choose Electron Version (Use arrow keys)
        ^11.0.0
        ^12.0.0
      > ^13.0.0
      // 等待安裝完成
      

      錯誤修復1

      Electron安裝過程中有警告提示

       WARN  It is detected that you are using Vue Router. It must function in hash mode to work in Electron. Learn more at https://goo.gl/GM1xZG .
      

      大致意思就是 在electron中 vue 只能使用hash模式。history模式不支持
      找到文件目錄src\router\index.ts:1:1

      import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
      // 改為
      import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'
      

      找到文件目錄src\router\index.ts:20:1

      const router = createRouter({
        history: createWebHistory(process.env.BASE_URL),
        routes
      })
      // 改為
      const router = createRouter({
        history: process.env.IS_ELECTRON ? createWebHashHistory(process.env.BASE_URL) : createWebHistory(process.env.BASE_URL),
        routes
      })
      

      啟動項目

      $ npm run electron:serve
      

      錯誤修復2

      不出意外的話項目不能正常啟動

      -  Bundling main process...ERROR in src/background.ts:63:56
      TS2571: Object is of type 'unknown'.
          61 |       await installExtension(VUEJS3_DEVTOOLS)
          62 |     } catch (e) {
        > 63 |       console.error('Vue Devtools failed to install:', e.toString())
             |                                                        ^
          64 |     }
          65 |   }
          66 |   createWindow()
      

      ts規范下模板也逃不過,找到文件src/background.ts:63:56

      try {
        await installExtension(VUEJS3_DEVTOOLS)
      } catch (e) {
        console.error('Vue Devtools failed to install:', e.toString())
      }
      // 改為
      try {
        await installExtension(VUEJS3_DEVTOOLS)
      } catch (e: any) {
        console.error('Vue Devtools failed to install:', e.toString())
      }
      

      錯誤修復3

      禍不單行,提示方法找不到

      error  in ./src/background.ts
      
      Module build failed (from ./node_modules/ts-loader/index.js):
      TypeError: loaderContext.getOptions is not a function
          at getLoaderOptions (E:\workCode\test\electron2vue3\project\node_modules\ts-loader\dist\index.js:91:41)
          at Object.loader (E:\workCode\test\electron2vue3\project\node_modules\ts-loader\dist\index.js:14:21)
      
       @ multi ./src/background.ts
      

      使用ts-loader@~8.2.0

      $ npm i ts-loader@~8.2.0 -D
      

      錯誤修復4

      啟動過程要等待很長時間,這是因為installExtension方法會持續請求安裝VUEJS3_DEVTOOLS,然后導致項目啟動非常慢,必須等它五次請求超時后,才能啟動項目

      INFO  Launching Electron...
      Failed to fetch extension, trying 4 more times
      Failed to fetch extension, trying 3 more times
      Failed to fetch extension, trying 2 more times
      Failed to fetch extension, trying 1 more times
      Failed to fetch extension, trying 0 more times
      Vue Devtools failed to install: Error: net::ERR_CONNECTION_TIMED_OUT
      libpng warning: iCCP: cHRM chunk does not match sRGB
      

      找到文件src/background.ts:5:1

      import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'
      // 注釋掉
      // import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'
      

      找到文件src/background.ts:60:5

      try {
        await installExtension(VUEJS3_DEVTOOLS)
      } catch (e: any) {
        console.error('Vue Devtools failed to install:', e.toString())
      }
      // 注釋掉
      // try {
      //   await installExtension(VUEJS3_DEVTOOLS)
      // } catch (e: any) {
      //   console.error('Vue Devtools failed to install:', e.toString())
      // }
      

      錯誤修復5

      如果我們將頁面改為setup語法糖就會出現以下錯誤

      'defineProps' is not defined  no-undef
      

      找到文件.eslintrc.js:4:1

      // 在env里加入屬性
      'vue/setup-compiler-macros': true
      

      安裝sqlite3

      $ npm install sqlite3@5.0.0 -s  
      $ npm install @types/sqlite3@3.1.8 -s
      

      安裝完成后在src/main.ts:7:1插入如下代碼進行測試

      import sqlite3 from 'sqlite3'
      console.log(sqlite3)
      

      錯誤修復6

      加入sqlite3測試代碼后頁面出現數不清的報錯,這是因為vue配置中沒有添加node支持
      找到文件vue.config.js:4:1

      // exports對象中加入配置
      pluginOptions:{
        electronBuilder:{
          nodeIntegration:true
        }
      }
      

      package.json

      {
        "name": "project",
        "version": "0.1.0",
        "private": true,
        "scripts": {
          "serve": "vue-cli-service serve",
          "build": "vue-cli-service build",
          "lint": "vue-cli-service lint",
          "electron:build": "vue-cli-service electron:build",
          "electron:serve": "vue-cli-service electron:serve",
          "postinstall": "electron-builder install-app-deps",
          "postuninstall": "electron-builder install-app-deps"
        },
        "main": "background.js",
        "dependencies": {
          "@types/sqlite3": "^3.1.8",
          "core-js": "^3.8.3",
          "sqlite3": "^5.0.0",
          "vue": "^3.2.13",
          "vue-router": "^4.0.3",
          "vuex": "^4.0.0"
        },
        "devDependencies": {
          "@types/electron-devtools-installer": "^2.2.0",
          "@typescript-eslint/eslint-plugin": "^5.4.0",
          "@typescript-eslint/parser": "^5.4.0",
          "@vue/cli-plugin-babel": "~5.0.0",
          "@vue/cli-plugin-eslint": "~5.0.0",
          "@vue/cli-plugin-router": "~5.0.0",
          "@vue/cli-plugin-typescript": "~5.0.0",
          "@vue/cli-plugin-vuex": "~5.0.0",
          "@vue/cli-service": "~5.0.0",
          "@vue/eslint-config-typescript": "^9.1.0",
          "electron": "^13.0.0",
          "electron-devtools-installer": "^3.1.0",
          "eslint": "^7.32.0",
          "eslint-plugin-vue": "^8.0.3",
          "sass": "^1.32.7",
          "sass-loader": "^12.0.0",
          "ts-loader": "^8.2.0",
          "typescript": "~4.5.5",
          "vue-cli-plugin-electron-builder": "~2.1.1"
        }
      }
      
      posted @ 2023-03-17 13:45  杜柯楓  閱讀(1672)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久亚洲国产品一区二区| 性欧美vr高清极品| 亚洲一区二区三区在线观看精品中文| 亚洲国产精品一二三四区| 无码人妻丝袜在线视频| 亚洲熟妇精品一区二区| 亚洲精品日韩中文字幕| 欧美精品日韩精品一卡| 激情国产一区二区三区四区 | 九九热精品在线视频观看| 猫咪AV成人永久网站在线观看| 国产精品亚洲综合色区丝瓜| 性久久久久久| 亚洲精品一区二区三区蜜| 熟女一区二区中文字幕| 国产首页一区二区不卡| 少妇av一区二区三区无码| 中文字幕在线日韩一区| 人妻有码av中文字幕久久琪| 亚洲 丝袜 另类 校园 欧美| 国产一区二区三区AV在线无码观看| 亚洲AV无码AV在线影院| 宁海县| 久久精品无码免费不卡| 自偷自拍亚洲综合精品| 中国女人高潮hd| 99re6这里有精品热视频| 欧美丰满妇大ass| 国产精品一区中文字幕| 爱性久久久久久久久| 高要市| 午夜国产精品福利一二| 扒开粉嫩的小缝隙喷白浆视频| 国产综合欧美| 久久天天躁狠狠躁夜夜躁2o2o| 欧美叉叉叉bbb网站| 亚洲中文字幕精品无人区| 久青草国产在视频在线观看| 亚洲午夜无码久久久久蜜臀AV| 狠狠人妻久久久久久综合蜜桃| 国产精品女在线观看|