使用 preact 多端开发(小程序和Web),基于 kbone 的 element 和 render。
- 使用最好的 react web 框架 preact,轻量迅速(react 不是最好的 react web 框架)
- 由于 3kb preact 加持,生成出的包大小超级小!!
import{h}from'preact'import{useState}from'preact/hooks'import'./index.css'functionCounter(){const[count,setCount]=useState(0)return(<div><buttononClick={()=>setCount(count-1)}>-</button><span>{count}</span><buttononClick={()=>setCount(count+1)}>+</button><divonClick={clickHandle}>跳转</div></div>)}functionclickHandle(){if('undefined'!=typeofwx&&wx.getSystemInfoSync){wx.navigateTo({url: '../log/index?id=1',})}else{location.href='log.html'}}exportdefaultCounternpx kbone-cli init my-app
cd my-app
npm run mp // 开发小程序
npm run build:mp // 构建小程序
npm run web // 开发 web
npm run build // 构建 web
├─ dist
│ ├─ mp // 微信开发者工具指向的目录,用于生产环境
│ ├─ web // web 编译出的文件,用于生产环境
├─ build // 构建相关
├─ src
│ ├─ assets
│ ├─ components // 存放所有组件
│ ├─ log.jsx // 入口文件,会 build 成 log.html
│ └─ index.jsx // 入口文件,会 build 成 index.html
preact 并没有提供根组件实例的销毁方法(如 vue.$destroy),所以在多页应用中页面关闭时不会触发该页面组件的 componentWillUnmount 钩子。开发者可自行监听 wxunload 或 beforeunload 事件来进行页面的销毁工作,比如调用 render 方法渲染一个空节点,强行触发页面组件的 componentWillUnmount 钩子。
![]() | ![]() | 告诉我们 |
MIT

