• className 拼接

cnpm i classnames —save

  1. <ul className="nav nav-pills">
  2. {
  3. files.map(file => {
  4. const fClassName = classnames({
  5. 'nav-link': true,
  6. 'active': file.id === activeId
  7. })
  8. return (
  9. <li className="nav-item" key={file.id}>
  10. <a href="#"
  11. className={fClassName}
  12. onClick={(e)=>{e.preventDefault(); onTabClick(file.id)}}
  13. >
  14. {file.title}
  15. </a>
  16. </li>
  17. )
  18. })
  19. }
  20. </ul>
  • 使用scss

cnpm i node-sass —save

  • 使用md编辑器

cnpm i —save react-simplemde-editor

在根函数中创建的 依赖性的函数会随着变量改变而改变, 如果某组件没有改变, key变量

生成唯一id

  • cnpm i —save uuid
    1. import uuidv4 from 'uuid/v4'
    2. let newId = uuidv4()

把数组循环找id 改为 map格式 id为key

  1. {
  2. '1': {...File}
  3. }
  • 新建个公用函数 处理
  1. const newFile = {...files[id], body: value}
  2. // 变量当key 用中括号
  3. setFiles({...files, [id]: newFile})

electron 导入 fs

  1. const fs = window.require('fs').promises

获取文件路径

  1. app.getPath(name)

数据持久化

  1. cnpm i electron-store --save
  2. const Store = window.require('electron-store')
  3. const store = new Store()
  4. store.set('name', 'Amy')
  5. console.log(store.get('name'))
  6. store.delete('name')

页面不渲染

  1. delete files[id]
  2. setFiles(files)
  3. 使用下面的
  4. setFiles({...files})

关闭拦截

  1. mainWindow.on('close', (e) => {
  2. e.preventDefault()
  3. let choice = dialog.showMessageBox(mainWindow, {
  4. type: 'info',
  5. title: 'Information',
  6. message: '确定要关闭吗?',
  7. buttons: ['最小化','直接退出']
  8. });
  9. choice.then(res => {
  10. if (res.response === 1) {
  11. mainWindow = null
  12. app.exit()
  13. }
  14. // if (res.response === 0) {
  15. // mainWindow.maximize()
  16. // }
  17. })
  18. // const choice = dialog.showMessageBoxSync(this, {
  19. // type: 'info',
  20. // title: 'Information',
  21. // defaultId: 0,
  22. // message: '确定要关闭吗?',
  23. // buttons: ['最小化','直接退出']
  24. // })
  25. // if (choice === 0) {
  26. // e.preventDefault()
  27. // }
  28. })
  • 单例

    1. app.requestSingleInstanceLock() 只打开一个窗口
  • 文档

https://umbrella22.github.io/electron-vue-template-doc/Overview/essentials/build.html#构建出web版本