Skip to content

Commit 6718589

Browse files
committed
test: 打包测试区分props和attrs功能
1 parent c92c981 commit 6718589

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { h, ref } from '../../lib/vue3.esm.js'
2+
import Child from './cpns/Child.js'
3+
export default {
4+
name: 'App',
5+
setup() {
6+
const age = ref(18)
7+
const handleClick = () => {
8+
console.log(111)
9+
age.value++
10+
}
11+
return { handleClick, age }
12+
},
13+
render() {
14+
return h('div', {}, [
15+
h('div', 'text App'),
16+
h(Child, {
17+
// 这里会进行了统一的规范: name & age 如果是props 则会在组件内部通过defineProps进行定义 其余的属性统一当做attrs(即不属于props的都会被当成attrs)
18+
name: 'coderwei',
19+
age: this.age,
20+
number: 95527666,
21+
cart: 'bar'
22+
}),
23+
h('button', { onClick: this.handleClick }, 'add')
24+
])
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { h } from '../../../lib/vue3.esm.js'
2+
export default {
3+
name: 'child',
4+
props: {
5+
name: {
6+
type: String,
7+
default: 'coder'
8+
},
9+
age: {
10+
type: Number
11+
}
12+
},
13+
setup() {},
14+
render() {
15+
return h('div', `age:${this.age}`)
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Document</title>
9+
</head>
10+
<div id="app"></div>
11+
12+
<body>
13+
14+
<script type="module">
15+
import {createApp} from '../../lib/vue3.esm.js'
16+
import App from './App.js'
17+
createApp(App).mount(document.querySelector("#app"))
18+
</script>
19+
20+
</body>
21+
22+
</html>

0 commit comments

Comments
 (0)