读了一个 Vue3 学习项目 chalk.ist(https://github.com/Idered/chalk.ist)的源码。光看 Vue3 组合式 API 的文档会让我有点迷茫,对着实际项目再去查有疑问的部分,带着问题找答案的感觉,理解会更深。读完整个项目后的感受: 单文件组件语法糖——顶层的绑定会直接暴露给模板,有点 Svelte 那味道;项目里用了 vite-plugin-pages(https://github.com/hannoeru/vite-plugin-pages)和 vite-plugin-vue-layouts(https://github.com/JohnCampionJr/vite-plugin-vue-layouts),让 Vue 项目的路由基于文件系统自动生成,省去了像 Next.js、Nuxt.js 那样手动注册路由;用 pica(https://github.com/nodeca/pica)在浏览器里 resize 图片,配合按比例裁剪图片的方法,做了 Twitter 头像上传那种前端处理;用 VueUse 里的 Hooks 解决通用问题,比如 useStorage、useElementSize、useFuse(JS 模糊搜索)。
6 月 12 日 星期日
看了 egoist/website(https://github.com/egoist/website)这个 Next.js 项目的源码。这是服务端渲染(Next.js 的 getServerSideProps),自己维护了数据库,用 Prisma 做查询,还有自己的管理后台——跟我自己写博客用的静态生成(getStaticProps)不一样,静态生成也是现在搭博客比较流行的方式。不过 egoist 前几天又改了,把博客部分删掉了,可以翻历史 commit 看,下面这张截图是跑在我本地的。
最近看了不少全栈项目,有些需要 Postgres、MongoDB、Redis 这些数据库。自己懒得去装数据库,之前是用 doko(https://github.com/egoist/doko)跑在本地 Docker 里,但如果需要公网能访问的数据库就不行了。发现 Railway 启动一个数据库实例 10 秒就能搞定,真的太好用了。
Railway | The all-in-one intelligent cloud providerRailway is a full-stack cloud for deploying web apps, servers, databases, and more with automatic scaling, monitoring, and security.railway.app
看到一条讲"状态机"写法的 tweet:某个状态是在几个固定的状态枚举之间轮转的话,可以用这种更好读的方式来写。
Cory House (@housecor) on X#10: State Enums are 🔥. With simple state enums, you likely don’t need XState and state charts (though they are nice).twitter.com
用 json-server(https://github.com/typicode/json-server)做 Mock 接口,太简单了,只要写一个 db.json 文件就够了,还支持增删改操作,这点很惊喜:如果发出 POST、PUT、PATCH 或 DELETE 请求,更改会用 lowdb 自动安全地保存到 db.json。




