Skip to content

Commit 3f3359b

Browse files
committed
chore: adjust
1 parent 5e4555e commit 3f3359b

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

demo/23-counter.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<script>
3030
console.log('MiniVue:', MiniVue)
3131
const { createApp, ref } = MiniVue
32-
const count = ref(0)
33-
32+
3433
createApp({
3534
setup() {
35+
const count = ref(0)
3636
const plus = () => {
3737
count.value++
3838
}

demo/24-render-function-options.html renamed to demo/24-counter-using-render-function-options.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
<div id="app"></div>
2222
<script>
2323
const { createApp, ref, h } = MiniVue
24-
const count = ref(0)
25-
24+
2625
createApp({
2726
setup() {
27+
const count = ref(0)
2828
const plus = () => {
2929
count.value++
3030
}

slides.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ render()
22192219
props: {
22202220
class: 'red',
22212221
onClick() {
2222-
console.log('click')
2222+
console.log('click')
22232223
}
22242224
},
22252225
children: [
@@ -2339,12 +2339,13 @@ demo: `22-counter.html`
23392339
</div>
23402340
```
23412341

2342-
```js
2342+
```html
2343+
<script>
23432344
const { createApp, ref } = MiniVue
2344-
const count = ref(0)
23452345
23462346
createApp({
23472347
setup() {
2348+
const count = ref(0)
23482349
const plus = () => {
23492350
count.value++
23502351
}
@@ -2358,6 +2359,7 @@ createApp({
23582359
}
23592360
}
23602361
}).mount('#app')
2362+
<script>
23612363
```
23622364
23632365
</div>
@@ -2366,11 +2368,9 @@ createApp({
23662368
23672369
## 手写 render 函数
23682370
2369-
我们知道,Vue.js 中,可以手写 `render` 渲染函数,我们也来支持下
2371+
我们知道,Vue.js 支持 `render` 渲染函数选项,相比较模板,这种方式更加灵活,现在我们也来支持下
23702372
23712373
```js
2372-
// demo: 24-render-function-options.html
2373-
23742374
function createApp(options = {}) {
23752375
const app = {
23762376
mount(container) {
@@ -2382,12 +2382,57 @@ function createApp(options = {}) {
23822382
render = compileToFunction(template)
23832383
}
23842384
// ...
2385+
const reload = () => {
2386+
const vnode = render(data)
2387+
// ...
2388+
}
2389+
effect(() => reload())
23852390
}
23862391
}
23872392
return app
23882393
}
23892394
```
23902395
2396+
---
2397+
2398+
支持了 `render` 渲染函数选项,现在我们使用 `render` 来重写下前面的 Counter 计数器 demo:
2399+
2400+
<div grid="~ cols-2 gap-2">
2401+
2402+
```html
2403+
<script src="./static/mini-vue.umd.js"></script>
2404+
<div id="app"></div>
2405+
```
2406+
2407+
```html
2408+
<script>
2409+
// demo: 24-render-function-options.html
2410+
const { createApp, ref, h } = MiniVue
2411+
createApp({
2412+
setup() {
2413+
const count = ref(0)
2414+
const plus = () => count.value++
2415+
const minus = () => count.value--
2416+
return {
2417+
count,
2418+
plus,
2419+
minus
2420+
}
2421+
},
2422+
render(props) {
2423+
const { count, plus, minus } = props
2424+
return h('div', { class: 'demo'}, [
2425+
h('button', { onClick() { minus() } }, '-1'),
2426+
h('span', { class: 'count' }, count),
2427+
h('button', { onClick() { plus() } }, '+1')
2428+
])
2429+
}
2430+
}).mount('#app')
2431+
</script>
2432+
```
2433+
2434+
</div>
2435+
23912436
---
23922437
layout: image
23932438
image: /mikoto-misaka.jpg

0 commit comments

Comments
 (0)