-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
65 lines (65 loc) · 1.47 KB
/
App.js
File metadata and controls
65 lines (65 loc) · 1.47 KB
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
55
56
57
58
59
60
61
62
63
64
65
import { reactive, h } from "./core/reactivity/index.js";
const App = {
render(context) {
// const dom = document.createElement("div");
// const textOne = document.createTextNode("num:");
// const textTwo = document.createTextNode(context.num); // 根据num的值变动
// const button = document.createElement("button");
// button.innerText = "add";
// button.addEventListener("click", () => {
// context.num++;
// });
// dom.append(textOne);
// dom.append(textTwo);
// dom.append(button);
// return dom;
/* virtual dom => h */
/* 当children为string类型时 */
// return h("div", { id: "capoo" }, "hello h function");
// [注意] 第三个值是children.
return h("div", { id: "capoo", class: "test" }, [
h(context.obj.tag, context.obj.propsUpdate, "count:"),
h(context.obj.tag, context.obj.propsAdd, String(context.obj.count)),
h(
"button",
{
onClick: () => {
context.obj.count + 1;
console.log("addCount");
},
...context.obj.propsRemove,
},
"addCount"
),
h(
"button",
{
onClick: () => {
context.obj.tag = "p";
console.log("changeTag");
},
},
"changeTag"
),
]);
},
setup() {
let obj = reactive({
count: 0,
tag: "span",
propsUpdate: {
a: "a1",
},
propsAdd: {
a: "a2",
},
propsRemove: {
a: "a3",
b: "b1",
},
});
window.obj = obj; // 为了方便调试,将obj挂载到window上
return { obj };
},
};
export default App;