Skip to content

Commit 74890ad

Browse files
committed
test(runtime-core): 编写组件attrs更新的测试例子 & 进行测试
1 parent 8ab62d7 commit 74890ad

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/vue/example/componentsAttrs/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export default {
1616
h(Child, {
1717
// 这里会进行了统一的规范: name & age 如果是props 则会在组件内部通过defineProps进行定义 其余的属性统一当做attrs(即不属于props的都会被当成attrs)
1818
name: 'coderwei',
19-
age: this.age,
20-
number: 95527666,
19+
age: 19,
20+
number: this.age,
2121
cart: 'bar'
2222
}),
2323
h('button', { onClick: this.handleClick }, 'add')

packages/vue/example/componentsAttrs/cpns/Child.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ export default {
1010
type: Number
1111
}
1212
},
13-
setup() {},
13+
setup(props, ctx) {
14+
const handleClick = () => {
15+
console.log(ctx.attrs.number)
16+
}
17+
return {
18+
handleClick
19+
}
20+
},
1421
render() {
15-
return h('div', `age:${this.age}`)
22+
return h(
23+
'div',
24+
{},
25+
h('div', `age:${this.age}`),
26+
h('button', { onClick: this.handleClick }, 'add3')
27+
)
1628
}
1729
}

0 commit comments

Comments
 (0)