(win环境)使用Electron打造一个桌面应用翻译小工具

在这里插入图片描述

初始化项目

npm init

修改package.json

{
“name”: “trans”,
“version”: “1.0.0”,
“main”: “main.js”,
“license”: “MIT”,
“scripts”: {
“start”: “electron .”,
“build”:“electron-packager . --overwrite --icon=./favicon.ico”
},
“devDependencies”: {
“electron”: “^9.0.5”
}
}

安装electron依赖

因为之前我们在package.json已经编辑过了devDependencies,所以我们直接。

npm install

创建编辑文件

分别创建两个文件index.html和main.js。
appid 与 key 需要自己去申请。这是网址:百度翻译编辑平台

index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>翻译小工具</title>
  <!-- https://electronjs.org/docs/tutorial/security#csp-meta-tag -->
  <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
  <style>
    input,textarea,select{ border: 1px solid #ccc;border-radius: 4px;font-family: Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,SimSun,sans-serif; }
    input { width: 100%; padding: 10px;box-sizing: border-box; margin: 20px 0;}
    textarea { display: block;padding: 10px ;  margin-top: 20px; width: 100%; height: 200px; text-align: left; resize: none; box-sizing: border-box; overflow: auto; }
    button{ width: 80px; height: 40px;border: none; background: #FFB90F; color: white; font-size: 14px; text-align: center; line-height: 40px; border-radius: 4px; cursor: pointer; margin-bottom:20px; }
    button:hover{ filter:brightness(110%); }
    button:active{ filter:brightness(60%); }
    select{padding: 10px;}
    .box { width: 750px; height: 600px; margin: 0 auto; }
  </style>
</head>

更多请见:http://www.mark-to-win.com/tutorial/50808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值