-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
54 lines (47 loc) · 1.18 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import {
reactive,
h,
} from './core/index.js';
export default {
// template -> render
render(context) {
// view
// view写死的 =》dom
// !dom情况如何处理
// 1. 公共逻辑需要抽离
// 2. 优化点 =》如何只更新变化了的view,实现最少更新?
// - vdom
// - diff
// reset
// document.querySelector('#app').textContent = '';
// const div = document.createElement('div');
// div.setAttribute('id', 'my-div');
// const p = document.createElement('p');
// p.textContent = 'p1';
// div.append(p);
// const p2 = document.createElement('p');
// p2.textContent = 'p2 --- ' + context.state.count;
// div.append(p2);
return h('div', context.state.props, context.state.children);
// document.querySelector('#app').append(div);
// return div;
},
setup() {
const state = reactive({
count: 1,
props: {
id: 'my-div',
class: 'red',
},
children: [
h('div', {id: 'child1'}, '123'),
h('div', {id: 'child2'}, '456'),
],
});
window.state = state;
window.h = h;
return {
state,
};
},
};