Snabbdom 是一个虚拟DOM库,重点放在简单性,模块化,强大的功能和性能上。
1.创建目录 如: mode
2. cnpm init -y
3. cnpm install parcel-bundler -D
4. 在更目录下新建 index.html 和 src文件夹,src 下面新建 01-main.js
5.在package.json 中配置
"scripts": {
"dev":"parcel index.html --open",
"build":"parcel build index.html"
},
6. 在github 网站中搜索 snabbdom
7. 安装 npm install snabbdom
8. 在01-main.js中:
import {init, h} from "snabbdom"
const patch = init([])
9.注册模块,及使用
// 1.导入模块
import{init,h,styleModule,eventListenersModule} from "snabbdom"
// 2.注册模块
const patch = init([
styleModule,
eventListenersModule
])
let vnode = h("div",[
h("h1",{style:{backgroundColor:"red"}},"yuqi"),
h("p",{on:{click:eventClick}},"hi p")
])
function eventClick(){
console.log("p");
}
let app = document.querySelector("#app")
patch(app,vnode)