Skip to content

Commit af7248d

Browse files
committed
init
1 parent 1ac7134 commit af7248d

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

Mini-Vue实现/index.html

Whitespace-only changes.

Mini-Vue实现/index.js

Whitespace-only changes.

Mini-Vue实现/mini-vue/index.js

Whitespace-only changes.

Mini-Vue实现/mini-vue/reactive.js

Whitespace-only changes.

Mini-Vue实现/mini-vue/render.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//h函数,用于返回一个VNode对象
2+
const h = (tag, props, children) => {
3+
//vnode -> javascript对象 -> {}
4+
return {
5+
tag,
6+
props,
7+
children
8+
}
9+
}
10+
11+
//mount函数,用于将VNode对象挂载到DOM上
12+
const mount = (vnode, container) => {
13+
//vnode -> element
14+
//1.创建出真实的原生,并且在vnode上保留element
15+
const element = vnode.el = document.createElement(vnode.tag)
16+
17+
//2.处理props
18+
if (vnode.props) {
19+
for (const key in vnode.props) {
20+
const value = vnode.props[key]
21+
22+
if (key.startsWith("on")) {
23+
element.addEventListener(key.slice(2).toLocaleLowerCase(), value)
24+
} else {
25+
element.setAttribute(key, value)
26+
}
27+
}
28+
}
29+
30+
//3.处理children
31+
if (vnode.children) {
32+
if (typeof vnode.children === 'string') {
33+
element.textContent = vnode.children
34+
} else {
35+
vnode.children.forEach(item => {
36+
mount(item, element)
37+
})
38+
}
39+
}
40+
41+
//4.将el挂载带container上
42+
container.appendChild(element)
43+
}
44+
45+
//pathch函数,用于对两个VNode进行对比,决定如何处理新的VNode
46+
const patch = (n1, n2) => {
47+
48+
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# Mini-Vue3
22
mini版的uve3框架
3+
4+
## 实现一个简约版的Mini-Vue3框架
5+
该框架主要包括三部分:
6+
1、**渲染系统模块**
7+
2、**可响应式系统模块**
8+
3、**应用程序入口模块**
9+
10+
### 渲染系统模块实现
11+
**渲染系统模块主要包含三个功能:**
12+
1.功能一:h函数,用于返回一个VNode对象
13+
2.功能二:mount函数,用于将VNode对象挂载到DOM上
14+
3.功能三:pathch函数,用于对两个VNode进行对比,决定如何处理新的VNode

0 commit comments

Comments
 (0)