File tree Expand file tree Collapse file tree 6 files changed +60
-0
lines changed
Expand file tree Collapse file tree 6 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11# Mini-Vue3
22mini版的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
You can’t perform that action at this time.
0 commit comments