<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lesson 31 render函数</title>
<script src="https://unpkg.com/vue@next"></script>
<style>
.red {
color: red;
}
</style>
</head>
<body>
<div id="root"></div>
<div id="hello"></div>
</body>
<script>
//render function
// template -> render -> h -> 虚拟DOM(JS对象) -> 真实 DOM -> 展示到页面上
const app = Vue.createApp({
template:
`<my-test :level="1">
hello dell
</my-test>
`
});
app.component('my-test',{
props:['level'],
render() {
const { h } = Vue;
//虚拟DOM
return h('h' + this.level, {}, [
this.$slots.default(),
h('h4', {class:'red'}, 'dell')
])
}
// template:
// `<h1 v-if=" level === 1 "><slot /></h1>
// `
})
app.mount('#root');
</script>
</html>
Vue render函数的用法
最新推荐文章于 2022-09-17 16:53:07 发布