Skip to content

Commit 1cf5c20

Browse files
committed
demo: add componentUpdate
1 parent 18c1b35 commit 1cf5c20

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

example/componentUpdate/App.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// 在 render 中使用 proxy 调用 emit 函数
2+
// 也可以直接使用 this
3+
// 验证 proxy 的实现逻辑
4+
import { h, ref, reactive } from "../../lib/mini-vue.esm.js";
5+
import Child from "./Child.js";
6+
7+
export default {
8+
name: "App",
9+
setup() {
10+
const msg = ref("123");
11+
12+
const changeChildProps = () => {
13+
msg.value = "456";
14+
};
15+
16+
return { msg, changeChildProps };
17+
},
18+
19+
render() {
20+
return h("div", {}, [
21+
h("div", {}, "你好"),
22+
h(
23+
"button",
24+
{
25+
onClick: this.changeChildProps,
26+
},
27+
"change child props"
28+
),
29+
h(Child, {
30+
msg: this.msg,
31+
}),
32+
]);
33+
},
34+
};

example/componentUpdate/Child.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { h, ref, reactive } from "../../lib/mini-vue.esm.js";
2+
export default {
3+
name: "Child",
4+
setup(props, { emit }) {},
5+
render(proxy) {
6+
const self = this;
7+
return h("div", {}, [h("div", {}, "child")]);
8+
},
9+
};

example/componentUpdate/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
<script type="module">
11+
import { createApp } from "../../../lib/mini-vue.esm.js";
12+
import App from "./App.js";
13+
14+
const rootContainer = document.querySelector("#app");
15+
createApp(App).mount(rootContainer);
16+
</script>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)