electron-vue+ts 搭建项目

it2025-04-01  7

## 1. 搭建electron-vue项目: ```js 全局安装vue/cli: npm install -g @vue/cli 创建项目my-project:vue init simulatedgreg/electron-vue my-project 进入项目my-project:cd my-project 初始化项目:npm install 启动项目:npm run dev 单元测试:npm run test electron-vue加入Ts参考:https://blog.csdn.net/weixin_44872699/article/details/108976677 ``` ## 2. electron-vue运行报错: process is not defined,在webpack.renderer.config.js和webpack.web.config.js 文件中找到 HtmlWebpackPlugin 代码段并更改为如下代码: ```js new HtmlWebpackPlugin({ ...... templateParameters(compilation, assets, options) { return { compilation: compilation, webpack: compilation.getStats().toJson(), webpackConfig: compilation.options, htmlWebpackPlugin: { files: assets, options: options }, process } } }) ``` ## 3. Vue+ts里面this.$store问题:解决办法:(this as any).$store ## 4. vue-electron脚手架进行vuex赋值时,失败的解决办法:https://segmentfault.com/a/1190000018038529?utm_source=tag-newest ```js 1. 去掉renderer/store/index.js中的createSharedMutations插件 2. 在主进程中加:import '../renderer/store' ``` ## 5. 窗口拖拽/禁止拖拽: ```css .drag{ -webkit-app-region: drag; } .no-drag{ -webkit-app-region: no-drag; } ``` ## 6. TypeScript 引入第三方包,报无法找到模块错误:参考:https://www.cnblogs.com/xym4869/p/13323483.html 和 https://www.jianshu.com/p/35742227738e ```txt 6.1 根据报错提示尝试安装该库的TypeScript版本 (该库的 ts 声明文件),也就是在该库的名称前加上 @types/。在方法一可行的情况下,推荐使用方法一但是,不是所有的第三方库都有 TypeScript 的版本 如: npm install @types/XXX 6.2 src/@types/,在 src 目录新建@types目录,在其中编写.d.ts声明文件,声明文件会自动被识别,可以在此为一些没有声明文件的模块编写自己的声明文件。 如: declare module 'XXX' { const content: any export = content } ``` ## 7. 多个this as any 连续使用报错,解决如下: ```js new Promise((resolve,reject)=>{ (this as any).newFriendList.splice(index,1) resolve('ok') }).then(()=>{ (this as any).$store.commit('SET_ADD_FRIEND_LIST',item) }) ```

 

最新回复(0)