<!DOCTYPE html>
<div id="app">
<anchored-heading :level="3">
<a name="hello-world" href="#hello-world">
Hello world!
</a>
</anchored-heading>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({
app.component('anchored-heading', {
render() {
const { h } = Vue
return h (
'h' + this.level,
{},
this.$slots.default()
)
},
props: {
level: {
type: Number,
required: true
}
}
})
})
app.mount("#app")
</script>
</html>
修改后
<!DOCTYPE html>
<div id="app">
<anchored-heading :level="3">
<a name="hello-world" href="#hello-world">
Hello world!
</a>
</anchored-heading>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({})
app.component('anchored-heading', {
render() {
const { h } = Vue
return h(
'h' + this.level,
{},
this.$slots.default()
)
},
props: {
level: {
type: Number,
required: true
}
}
})
app.mount('#app')
</script>
</html>
渲染字符的标题大小
把3改成1
<!DOCTYPE html>
<div id="app">
<anchored-heading :level="1">
<a name="hello-world" href="#hello-world">
Hello world!
</a>
</anchored-heading>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script>
const app = Vue.createApp({})
app.component('anchored-heading', {
render() {
const { h } = Vue
return h(
'h' + this.level,
{},
this.$slots.default()
)
},
props: {
level: {
type: Number,
required: true
}
}
})
app.mount('#app')
</script>
</html>