学习-vue3 非 prop 的 Attribute-多个根节点上的 Attribute 继承
多个根节点上的 Attribute 继承
与单个根节点组件不同,具有多个根节点的组件不具有自动 attribute fallthrough(隐式贯穿)行为,如果未显式绑定 $attrs,将发出运行时警告。
<custom-layout id="custom-layout" @click="changeValue"></custom-layout>
// 将发出警告
app.component('custom-layout', { template: ` <header>...</header> <main>...</main> <footer>...</footer> ` })
// 没有警告,$attrs 被传递到 <main> 元素
app.component('custom-layout', { template: ` <header>...</header> <main v-bind="$attrs">...</main> <footer>...</footer> ` })
fighting
浙公网安备 33010602011771号